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

130
Visualizações
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 Respostas
Responde à pergunta

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 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