for each javascript array of object code example
Example 1: javascript loop through array of objects
let arr = [object0, object1, object2];
for (let elm of arr) {
console.log(elm);
}
Example 2: iterate over array of objects javascript
const myArray = [{x:100}, {x:200}, {x:300}];
const newArray= myArray.map(element => element.x);
console.log(newArray);
Example 3: javascript foreach call specific value in array
run.addEventListener("click", function () {
people.forEach((element) => console.log(element.firstname));
});
Example 4: javascript foreach
const colors = ['blue', 'green', 'white'];
function iterate(item) {
console.log(item);
}
colors.forEach(iterate);