Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
I would like to only select the second object in an array within a map function

so I created a bar chart using Chart Js. So by using props I would like to change the labels of datasets one and two. The thing is my prop is set up in such a way due to the use in other graphs, that they have two objects inside. I only want to use, for example, object 2(in the object array) name for dataset two's label. I hope this makes sense.

I know you can use the map function to take all the object names, but I only want one..

                datasets: [
              {
                label: props.data.map((o) => o.Name),
                data: props.data.map((o) => o.Size),
                borderColor: 'rgba(181, 156, 201, 1)',
                backgroundColor: 'rgba(181, 156, 201, 0.75)'

              },
              {
                label: props.data.map((o) => o.Name),
                data: props.data.map((o) => o.Size),
                borderColor: 'rgba(131, 90, 165, 1)',
                backgroundColor: 'rgba(131, 90, 165, 0.75)',
              },

What the set up above gives me Bar Chart with two datasets

This is my useState set

            setObjectOneIfo([InfoOne, InfoTwo])

And this is what I get in my console What I get in my console

Maybe I'm missing something. Any help would be largely appreciated.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

          datasets: [
              {
                  label: props.data.map((o) => o.Name[1]), //Just put the index number you want behind name in square brackets
                  data: props.data.map((o) => o.Size),
                  borderColor: 'rgba(181, 156, 201, 1)',
                  backgroundColor: 'rgba(181, 156, 201, 0.75)'

              },
              {
                 label: props.data.map((o) => o.Name),
                 data: props.data.map((o) => o.Size),
                 borderColor: 'rgba(131, 90, 165, 1)',
                 backgroundColor: 'rgba(131, 90, 165, 0.75)',
              }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!