Object.entries()

Returns an array of an object's own enumerable [key, value] pairs.

Since ES2017 Spec ↗

Syntax

Object.entries(obj)

Parameters

NameTypeRequiredDescription
obj object Yes The object whose enumerable own [key, value] pairs are returned.

Returns

Array — An array of [key, value] pair arrays.

Examples

console.log(Object.entries({ a: 1, b: 2 }));
Output
[ [ 'a', 1 ], [ 'b', 2 ] ]
for (const [k, v] of Object.entries({ x: 9 })) console.log(k, v);
Output
x 9

Notes

Great for iterating an object with `for...of` and destructuring, or for building a Map via `new Map(Object.entries(obj))`. The inverse is `Object.fromEntries`.

Browser & runtime support

EnvironmentSince version
chrome 54
firefox 47
safari 10.1
edge 14
node 7.0

See also