DEV Community

Discussion on: How to iterate over objects using array methods

Collapse
 
wintercounter profile image
Victor Vincent

How about:

for (const [key, value] of Object.entries(obj)) {
    console.log(key, value)
}

So much cleaner! People usually just scratching the surface of what JS can actually do.

Collapse
 
robaxelsen profile image
Robert Axelsen • Edited

Beautiful! This one is also nice:

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