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

95
Visualizações
failed looping through array with two value pairs

I'm trying to loop through this array

const test = [(18, 20), (45, 2), (61, 12), (37, 6), (21, 21), (78, 9)];

but it's output looks like this

console.log(test); //[20, 2, 12, 6, 21, 9]

please let me know how to loop through this array correctly .

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

0

The problem isn't the looping (though you haven't shown any looping in your question). Your array starts out with just the values 20, 2, 12, etc. in it. (18, 20) evaluates to 20, because the comma operator evaluates its left-hand operand (18), throws that away, and evaluates its right-hand operand and takes that value as its result.

If you wanted an array of tuples, you wanted [], not (), on the inner arrays:

const test = [[18, 20], [45, 2], [61, 12], [37, 6], [21, 21], [78, 9]];
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