EN
JavaScript - forEach over array with objects
3
points
In this article, we would like to show you forEach()
method used to loop over an array with objects in JavaScript.
The forEach()
method calls provided function once for each element of an array. In this case, we have an array of objects.
Runnable example:
// ONLINE-RUNNER:browser;
var users = [
{name: 'Thomas', age: '21'},
{name: 'Mark', age: '35'}
];
users.forEach((user) => {
console.log(user.name, user.age);
});
Output:
Thomas, 21
Mark, 35
Note:
Here you can read more about how to useforEach
.