JavaScript iterate iterate Object Key Valores
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});
Jealous Jay
Object.entries(obj).forEach(([key, value]) => {
console.log(key, value);
});
var myObject = { 'a': 1, 'b': 2, 'c': 3 };
Object.keys(myObject).map(function(key, index) {
myObject[key] *= 2;
});
console.log(myObject);
// => { 'a': 2, 'b': 4, 'c': 6 }
for (const [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
const map = new Map(Object.entries({foo: 'bar'}));
map.get('foo'); // 'bar'
Object.fromEntries(Map)
let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
let obj = Array.from(map).reduce((obj, [key, value]) => (
Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});
console.log(obj); // => { a: 1, b: 2, c: 3 }