iterate over object keys and values javascript code example
Example 1: iterate key value object javascript
'use strict';
const object = {'a': 1, 'b': 2, 'c' : 3};
for (const [key, value] of Object.entries(object)) {
console.log(key, value);
}
Example 2: loop over keys in object javascript
Object.keys(obj).forEach(function(key) {
console.log(key, obj[key]);
});
Example 3: 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 4: javascript iterate object key values
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});