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

244
Views
How to map through an object in JavaScript and extract nested data?

I'm trying to iterate through this data structure to generate a Graph. But I couldnt figure out how to map through my Objects.

{
 "dP008S002D007":[
   571.8619718309859,
   604.5888966971188
  ],
 "dP009S002D007":[
   1445.2859154929577,
  1503.5495432185523
 ]
}

dp00... will be my line. So I'll map over this object and generate a Line, the values inside the array will be my data. But I cant figure out how to map over this structure. This was a dictionary and I managed to reduce to this. Here is my code.

  const chartPoints = useMemo(() => {
    const history = iotData?.history?.[location.id].sensors || [];
    const chartPoints = {};
    const findPoints = Object.keys(history).map((key) => {
      chartPoints[key] = history[key].map((data) => data.avg);
    });
    return chartPoints;
  }, [iotData?.history, location.id]);

It'll be ideal if I could return:

[
 "dP008S002D007":[
   571.8619718309859,
   604.5888966971188
  ],
 "dP009S002D007":[
   1445.2859154929577,
  1503.5495432185523
 ]
]

Or map over these objects. Can Anybody help me with this? Thanks for all.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As some answered to your question, you can't make a variable like you wanted in your output. But, because you just want to iterate throught your input you can use the for...in

In a for...in you can iterate like this :

for(key in obj) {
//key is the name of the key like "dP009S002D007"
//obj[key] is the value like [1445.2859154929577,1503.5495432185523]
}

else you can also transform your whole object as array of array with this one :

let table = []
for(key in obj) {
    table.push([key, ...obj[key]])
}

it produces 1 array containing 2 arrays like this :

[ [ 'dP008S002D007', 571.8619718309859, 604.5888966971188 ],
[ 'dP009S002D007', 1445.2859154929577, 1503.5495432185523 ] ]

You will then be able to use .map on the table and do what you wanted.

about 4 years ago · Juan Pablo Isaza 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!