iterate array or object in js code example
Example 1: js loop through object
const obj = { a: 1, b: 2 };
Object.keys(obj).forEach(key => {
console.log("key: ", key);
console.log("Value: ", obj[key]);
} );
Example 2: iterate through object array javascript
for (var key in array) {
var obj = myArray[key];
// ...
}
Example 3: 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
}