ES 6: Using Object.entries() to iterate the keys in the Object
Chaitanya Chunduri
Posted on July 25, 2019
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}`);
}
or there is another way using forEach method
Object.entries(employe).forEach(([key, value]) => {
console.log(`${key}: ${value}`);
});
Object.enttries() got standardised in ECMAScript2017. Below is the browser support chart collected from MDN
💖 💪 🙅 🚩
Chaitanya Chunduri
Posted on July 25, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined JavaScript and SaaS: The Dynamic Duo Behind Scalable and Interactive Applications
November 17, 2024