JavaScript Object.entries()
- Previous page defineProperty()
- Next page freeze()
- Go back to the previous level JavaScript Object Reference Manual
Definition and usage
Object.entries()
The method returns an array of object key-value pairs.
Object.entries()
The method does not change the original object.
Related methods:
Object.keys()
Returns any object type's keys (properties).
Object.values()
Returns all object keys (properties) values.
Object.entries()
Returns any object type's keys and values.
The above methods return iterable objects (enumerable arrays).
Iterables make it easier to use objects in loops and convert objects to Maps.
Instance
Example 1
const person = { firstName: "Bill", lastName: "Gates", age: 50, eyeColor: "blue" }; let text = Object.entries(person);
Example 2
Object.entries()
Making it easier to use objects in loops:
const fruits = {Bananas: 300, Oranges: 200, Apples: 500}; let text = ""; for (let [fruit, value] of Object.entries(fruits)) { text += fruit + ": " + value + "<br>"; }
Example 3
Object.entries()
Making it easier to convert an object to a Map:
const fruits = {Bananas: 300, Oranges: 200, Apples: 500}; const myMap = new Map(Object.entries(fruits));
Syntax
Object.values(object)
Parameter
Parameter | Description |
---|---|
object | Optional. Object. |
Return value
Type | Description |
---|---|
Array | an iterable array containing object key-value pairs. |
Browser support
ECMAScript 2017 added Object.entries()
Method.
Since March 2017, all modern browsers support Object.entries()
:
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 47 | Edge 14 | Firefox 47 | Safari 10.1 | Opera 41 |
June 2016 | August 2016 | June 2016 | March 2017 | October 2016 |
- Previous page defineProperty()
- Next page freeze()
- Go back to the previous level JavaScript Object Reference Manual