iterate over object in javascript code example
Example 1: javascript loop through object
Object.entries(obj).forEach(
([key, value]) => console.log(key, value)
);
Example 2: javascript iterate through object attributes
for (var prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
// do stuff
}
}
Example 3: javascript iterate over object
for (variable in object)
statement