Quantcast
Channel: Iterate through object properties - Stack Overflow
Viewing all articles
Browse latest Browse all 35

Answer by Isaac Sichangi for Iterate through object properties

$
0
0

If you have an array of objects with their properties e.g

let students = [{name:"John", gender:"male", yob:1991},{name:"Mary", gender:"female", yob:1994} ]

You can iterate over the properties in 2 ways

  1. Using the for of loop in Javascript

    for(let student of students){ //access the properties here student.name student.gender student.yob }
  2. Using the for each loop in Javascript

 students.forEach(function(value, index, arr){  //access properties here  value.name  value.gender  value.yob });

Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>