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

115
Vistas
For loop and for of loops not showing array value?

I have an array like this:

let arr = ["zero", "one", "two"]; // I'm an indexed array!
arr.foo = "bar";

If I try accessing arr.foo, it's accessible:

console.log(arr.foo); // Returns "bar"

However, if I loop over this array with for loop like this:

for (let i = 0; i <= arr.length; i++) {
  console.log(`${i} => ${arr[i]}`);
}

I get this:

0 => zero
1 => one
2 => two
3 => undefined

Also, if I use for in loop like this:

for (let y in arr) {
  console.log(y);
}

I get indexes, including foo:

0
1
2
foo

But if I use for of like this:

for (let z of arr) {
  console.log(z);
}

I get this:

zero
one
two

So foo value is missing in both for and for of loops!

Question is, why is foo inaccessible inside of these loops? Why does it say its undefined, when I can access it using arr.foo?

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