DEV Community

Chaitanya Chunduri
Chaitanya Chunduri

Posted on

1 1

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay