DEV Community

Chaitanya Chunduri
Chaitanya Chunduri

Posted on

ES 6: Using Object.entries() to iterate the keys in the Object

You can iterate keys in an object using ES 6 like below.

let employe = {
 name: 'Chaitanya',
 eno: '1'
};

for (let [key, value] of Object.entries(employe)) {
  console.log(`${key}: ${value}`);
}
Enter fullscreen mode Exit fullscreen mode

or there is another way using forEach method

Object.entries(employe).forEach(([key, value]) => {
  console.log(`${key}: ${value}`); 
});
Enter fullscreen mode Exit fullscreen mode

Object.enttries() got standardised in ECMAScript2017. Below is the browser support chart collected from MDN

Top comments (0)