InterviewHubPRO
Section Overview
Q204

Question 204 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

39%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

How do you get enumerable key and value pairs

The Object.entries() method is used to return an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for...in loop. Let's see the functionality of object.entries() method in an example,

javascript
  const object = {
    a: "Good morning",
    b: 100,
  };

  for (let [key, value] of Object.entries(object)) {
    console.log(`${key}: ${value}`); // a: 'Good morning'
    // b: 100
  }

Note: The order is not guaranteed as object defined.