Javascript - Object.entries() and Object.values()


Object.entries() and Object.values() are two new methods introduced in ES2017.

The Object.entries() method, when run on an object, returns the object's own enumerable property [key, value] pairs in the same order as that provided by a for-in loop.

It does not enumerate properties in the prototype chain.

Object.values() when passed an object returns an array of its own enumerable property values:


const myObj = { a: 1, b: 42 }; /*w w w .ja  va2 s .c  o m*/

Object.entries(myObj);     // [['a', 1], ['b', 42]] 

Object.values(myObj);      // [1, 42]