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

237
Vistas
Mapping through array in React with nested objects

For a school project, I am making a dashboard where I want to visualize some data. I've already got it so far that I can load the data into the front end which is react.

Now I want to get certain values ​​from the array. But since it's a fairly large array, I'm not exactly sure how to loop through this.

The data looks like this: enter image description here

I want to have the _value for each object so that I can eventually load it into a area chart from rechart.

The code for the areachart:

<AreaChart
    width={1550}
    height={400}
    data={this.getMachineData()}
    margin={{
        top: 10,
        right: 30,
        left: 0,
        bottom: 0,
    }}
>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis dataKey="_table" />
<Tooltip />
<Area type="monotone" dataKey="uv" stackId="1" stroke="#8884d8" fill="#8884d8" />
<Area type="monotone" dataKey="pv" stackId="1" stroke="#82ca9d" fill="#82ca9d" />
<Area type="monotone" dataKey="amt" stackId="1" stroke="#ffc658" fill="#ffc658" />
<Legend />
    <Bar dataKey="_value" fill="#8884d8" />
    <Bar dataKey="uv" fill="#82ca9d" />
</AreaChart>

I have already made a method but it is not implemented yet:

getMachineData(data) {
    console.log(data)
    const result = data.map((innerArray) => {
        console.log(innerArray)
        // Map over the inner array
        return innerArray.map((item) => {
            // Return an object with only the properties you need
            return ({
                time: item._time,
                value: item._value
            });
        });
    })
    console.log(result)
    return result;
};

I was thinking of looping through the object myself with the .map function but since they are objects within objects I'm not sure how to go about this.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not sure what you mean by objects within objects. What I see in the above image is an array (with 816 objects) inside an array. So a simpler way using the map function would be:

const data = [
  [
    { _time: 1, _value: 2 },
    { _time: 3, _value: 4 },
    { _time: 5, _value: 6 },
    { _time: 7, _value: 8 },
  ]
]

const results = []

// Map over the outer array
data.map((innerArray) => {
  // Map over the inner array
 return innerArray.map((item) => {
    // Return an object with only the properties you need
    results.push({
      time: item._time,
      value: item._value
    });
  });
})

console.log(results);

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