JavaScript Object.fromEntries()
Example
const fruits = [
["apples", 300],
["pears", 900],
["bananas", 500]
];
const myObj = Object.fromEntries(fruits);
Try it Yourself »
Description
The fromEntries()
method creates an object from
a list of key/value pairs.
See Also
Object.keys() returns the keys of an object.
Object.values() returns the values of an object.
Object.entries() returns the keys and values of an object.
All these methods return an enumerable (iterable) array. This makes it simpler to use objects in loops. It also makes it simpler to convert objects to maps.
Object.fromEntries() creates an object from a list of keys/values.
Syntax
Object.fromEntries(iterable)
Parameters
Parameter | Description |
iterable | Optional. An iterable array or map. |
Return Value
Type | Description |
An object | An object from the key/value pairs. |
Browser Support
ES2019 added the Object method fromEntries()
to JavaScript.
JavaScript Object fromEntries()
is supported in all modern browsers since January 2020:
Chrome 73 | Edge 79 | Firefox 63 | Safari 12.1 | Opera 60 |
Mar 2019 | Jan 2020 | Oct 2018 | Mar 2019 | Apr 2019 |