JavaScript Object.fromEntries()

Definition and usage

fromEntries() Method used to create an object from a list of key-value pairs.

Related methods:

Object.assign() Copy the properties of the source object to the target object.

Object.create() Create a new object from an existing object.

Object.fromEntries() Create an object from a list of key-value pairs.

Example

const fruits = [
  ["apples", 300],
  ["pears", 900],
  ["bananas", 500]
];
const myObj = Object.fromEntries(fruits);

Try it yourself

Syntax

Object.fromEntries(iterable)

Parameter

Parameter Description
iterable Optional. An iterable array or Map.

Return value

Type Description
Object objects created from key-value pairs.

browser support

ES2019 adds Object.fromEntries() method.

Starting from January 2020, all modern browsers support Object.fromEntries():

Chrome Edge Firefox Safari Opera
Chrome 73 Edge 79 Firefox 63 Safari 12.1 Opera 60
March 2019 January 2020 October 2018 March 2019 April 2019