Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda