for key value js code example
Example 1: foreach object javascript
const games = {
"Fifa": "232",
"Minecraft": "476"
"Call of Duty": "182"
};
Object.keys(games).forEach((item, index, array) => {
let msg = `There is a game called ${item} and it has sold ${games[item]} million copies.`;
console.log(msg);
});
Example 2: for key value in object javascript
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 3: get keys of object js
var buttons = {
foo: 'bar',
fiz: 'buz'
};
for ( var property in buttons ) {
console.log( property );
}