js for object key value code example
Example 1: javascript iterate over object keys and values
const object1 = {
a: 'somestring',
b: 42
};
for (let [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 2: javascript for key in object
const object = { a: 1, b: 2, c: 3 };
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
Example 3: for key value in object javascript
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 4: iterate over object javascript
Object.keys(pokemons).forEach(console.log);