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

422
Visualizações
javacsript array map with double [[ ]] data

I have this array:

[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]

how can i remove the first parenthesis? i tried with reduce or map but return an error:

Cannot read properties of undefined (reading 'reduce') or Cannot read properties of undefined (reading 'map').

I have to retrieve some data inside it.

Thanks for your help.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

you can use array.flat() here

let x =[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]

let y = x.flat()

console.log(y) // [ { data1: 1, data2: 2 }, { data1: 1, data2: 2 } ]
about 4 years ago · Santiago Trujillo Relatório

0

If your data is in an array arr, there are a couple of ways:

  1. Just do arr[0].map(...) (if your data looks like in your example)
  2. Use flatMap. If there is nesting like [ [ obj1, obj2 ], [ obj3, obj4 ] ] flatMap turns it to [obj1, obj2, obj3, obj4]

Example:

arr.flatMap(_ => _)

Edit: As others have mentioned, flat works just as well. It depends whether you want to perform some operations within the flatMap also, or to get an array of only the data1 properties of the objects in your example:

arr.flatMap(el => el["data1"]) 
about 4 years ago · Santiago Trujillo 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