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

135
Vistas
How to iterate through a array in JavaScript

Hi everyone I just started learning js. One of the assignment is to add all firstname from a list of students to an array. When I tried the following codes

    let students = [
    {
        fname: "Jam",
        lname: "Brazier",
        snum: "0010",

    },
    {
        fname: "Ricardo",
        lname: "Allen",
        snum: "0020",

    }]

and running

    for (let student in students) {
    console.log(student.fname);
}

Got undefined undefined from console. Why is this not working?

I also tried the following

let num_list = [2.99,5,6,3,2,4,5];
for (let num in num_list){
    console.log(num);
}

This time the output is index of each number:

0
1
2
3
4
5
6

How should I fix this code? Thanks a lot for your time.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The type of loop you need is a for... of loop.


Working Example:

let students = [
  {
    fname: "Jam",
    lname: "Brazier",
    snum: "0010",
  },

  {
    fname: "Ricardo",
    lname: "Allen",
    snum: "0020",
  }
]


for (let student of students) {
  console.log(student.fname);
}


Further Reading:

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
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