how to iterate over a list of object in js code example
Example 1: loop array of objects
const myArray = [{x:100}, {x:200}, {x:300}];
myArray.forEach((element, index, array) => {
console.log(element.x); // 100, 200, 300
console.log(index); // 0, 1, 2
console.log(array); // same myArray object 3 times
});
Example 2: iterate over array of object javascript and access the properties
for (let item of items) {
console.log(item); // Will display contents of the object inside the array
}