Object.entries()
Returns an array of an object's own enumerable [key, value] pairs.
Syntax
Object.entries(obj) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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
| Environment | Since version |
|---|---|
| chrome | 54 |
| firefox | 47 |
| safari | 10.1 |
| edge | 14 |
| node | 7.0 |