JS: Object.entries

By Xah Lee. Date: . Last updated: .

(new in ECMAScript 2017)

Object.entries(obj)
  • Convert object to Array.
  • Each property is converted to array [key, value].
  • Only consider properties that are own, string key, and Enumerable. Others are ignored.
  • Return the new array.
console.log(
 Object.entries({ dog: 3, cat: 4 }),
);
// [ [ "dog", 3 ], [ "cat", 4 ] ]
// verify the result is true array
console.assert(
 Array.isArray(Object.entries({ dog: 3, cat: 4 })),
);