for of loop object code example
Example 1: javascript loop through object
Object.entries(obj).forEach(
([key, value]) => console.log(key, value)
);
Example 2: object for loop
const object = {a: 1, b: 2, c: 3};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
Example 3: javascript looping through object
const fruits = {
apple: 28,
orange: 17,
pear: 54,
}
const values = Object.values(fruits)
console.log(values)
Example 4: use these instead of a for loop javascript
const array = [1, 2, 3];array.forEach(function(elem, index, array) { array[index] = elem * 2;});console.log(array);
Example 5: use these instead of a for loop javascript
const array = [1,2,3,4,5];const evenNumbers = array.filter(function(elem) {