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.
Related Methods:
Object.assign() copies properties from a source object to a target object.
Object.create() creates an object from an existing object.
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 |
Object | The object created 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 |