javascript iterate over object ES6 code example

Example 1: javascript iterate object key values

Object.entries(obj).forEach(([key, value]) => {
	console.log(key, value);
});

Example 2: js loop over 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

// For a functional one-liner
Object.keys(pokemons).forEach(console.log);
// Bulbasaur
// Charmander
// Squirtle
// Pikachu