Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda