For the longest time if I wanted to iterate thru an object in JavaScript I would write code that looked something like this:
const obj = { a: "foo", b: "bar" };
for (const key of Object.keys(obj)) {
console.info(key, obj[key]);
}
Since ES2017 there is a better way of doing this using Object.entries()
and destructuring:
const obj = { a: "foo", b: "bar" };
for (const [ key, value ] of Object.entries(obj)) {
console.info(key, value);
}
Read More