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

153
Vistas
How can I get all the object inside an object which is present inside an array and add the result into another array

I am struggling with an issue that is bugging me a lot. I am not good with JSON data manipulation.

So the issue is I have an Array of multiple Object which contain some data, Now inside these objects, I have another array of objects which I want

the JSON looks something like this-

const data = [{
  a: 2,
  b: 3,
  c: 4,
  d: [{
    e: 5,
    f: 4,
    g: 6,
  }, {
    h: 5,
    i: 4,
    j: 6,
  }]
}, {
  a: 11,
  b: 31,
  c: 42,
  d: [{
    e: 54,
    f: 46,
    g: 62,
  }, {
    h: 55,
    i: 42,
    j: 64,
  }]
}]

Now What I want is an Array which holds the following data

const d = [{
  e: 5,
  f: 4,
  g: 6,
}, {
  h: 5,
  i: 4,
  j: 6,
}, {
  e: 54,
  f: 46,
  g: 62,
}, {
  h: 55,
  i: 42,
  j: 64,
}]

I tried mapping over the data but I always end up with an array that look

const data = [
  [{
    e: 5,
    f: 4,
    g: 6,
  }, {
    h: 5,
    i: 4,
    j: 6,
  }],
  [{
    e: 54,
    f: 46,
    g: 62,
  }, {
    h: 55,
    i: 42,
    j: 64,
  }]

]

Not sure what am i doing wrong. need some help

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

0

You can loop over the data and then loop over the data.d again to get all of the required data. For each of the data, you push it into another array that you will later use.

const data = [{a:2,b:3,c:4,d:[{e:5,f:4,g:6,},{h:5,i:4,j:6,}]},{a:11,b:31,c:42,d:[{e:54,f:46,g:62,},{h:55,i:42,j:64,}]}]
let result = [];
data.forEach(d => d.d.forEach(dd => result.push(dd)));
console.log(result);

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