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

292
Visualizações
How to merge a multiple array structure from one array into one group of arrays? (JS)

I'm sure this is a dumb question but I'm really struggling with the syntax for this. In javascript I have this:

  const arr = [
[
  {
    test: "hey1",
  },
  
],
[
  {
    test: "hey2",
  },
  
],

]

This prints out like this:

 Array(2)
0: [{…}]
1: [{…}]

So accessing it right now is like this arr[0][1].test where i just want to be able to access the other arrays in the array like arr[1].test

Hope that makes sense and once again sorry for the dumb question!

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

If I understood your question correctly, you just want to remove one level of nested array. Easiest way would be to just enter the array level into a new array.

var newArray = arr[0];

You can also refer to this. Remove one level of nested arrays from JS data structure

about 4 years ago · Juan Pablo Isaza Relatório

0

If I understood you correctly you want to unite all the arrays you have into one array

open a new array variable

allArr=[]

And run in a loop on the old array by using Spread Operato

for (let i = 0; i < oldArr.length; i++) {
    allArr.push([...i])

    //OR
    
    allArr= [...allArr,...i]
    
}


about 4 years ago · Juan Pablo Isaza Relatório

0

As Emiel Zuurbier mentioned in the comments - you can simply use flat method:

const arr = [
[
  {
    test: "hey1",
  },
  
],
[
  {
    test: "hey2",
  },
  
],
].flat();

And now this will be your new arr:

enter image description here

Now you can access your element like this:

console.log(arr[0].test)
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