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

123
Visualizações
Should I use map/reduce/flatten functions to manipulate Multi-Dimensional Array in Javascript

I have this data :

[
["A","X1","Y1"],
["A","X2","Y2"],
["A","X3","Y3"],
["B","X4","Y4"],
["B","X5","Y5"],
["B","X6","Y6"],
]

and would like to change the array structure to be this :

[
["A",["X1","Y1"],["X2","Y2"],["X3","Y3"]],
["B",["X4","Y4"],["X5","Y5"],["X6","Y6"]],
]

I have been playing around with flatten function (flatten with a 'key' (i.e A and B) and then join all back together at the end.) - but the 'key' change from A to B (and potentially to C, D, E ....) has got me stumped.

I would appreciate any pointers as to the most efficient direction to go. Has any one else met this type of need ? Is there a better way (outside nested interations)

about 4 years ago · Juan Pablo Isaza
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