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

192
Vistas
Why does looping an array containing objects not return the object?

I have a simple array containing objects:

arr = [{"key": "foo"}, {"key": "bar"}]

If I loop it I should get a list of objects, but the result is just:

for (i in arr) {console.log(i)}
0
1

What's stranger is that if I'm lazy and not using console.log, the result is different:

for (i in arr) {i}
"1"

There is a lot of answers in How to loop through an array containing objects and access their properties. That is, I can use forEach() and get the expected result:

arr.forEach(i=>console.log(i) ) 
{key: "foo"}
{key: "bar"}

But that is how to fix it. I want to know why this happens.

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