Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!