Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

255
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda