| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its been available across browsers since January 2020.
The Object.fromEntries() static method transforms a list of key-value pairs into an object.
const entries = new Map([
["foo", "bar"],
["baz", 42],
]);
const obj = Object.fromEntries(entries);
console.log(obj);
// Expected output: Object { foo: "bar", baz: 42 }
Object.fromEntries(iterable)
iterableAn iterable, such as an Array or Map, containing a list of objects. Each object should have two properties:
Typically, this object is implemented as a two-element array, with the first element being the property key and the second element being the property value.
A new object whose properties are given by the entries of the iterable.
The Object.fromEntries() method takes a list of key-value pairs and returns a new object whose properties are given by those entries. The iterable argument is expected to be an object that implements a [Symbol.iterator]() method. The method returns an iterator object that produces two-element array-like objects. The first element is a value that will be used as a property key, and the second element is the value to associate with that property key.
Object.fromEntries() performs the reverse of Object.entries(), except that Object.entries() only returns string-keyed properties, while Object.fromEntries() can also create symbol-keyed properties.
Note:
Unlike Array.from(), Object.fromEntries() does not use the value of this, so calling it on another constructor does not create objects of that type.
With Object.fromEntries, you can convert from Map to Object:
const map = new Map([
["foo", "bar"],
["baz", 42],
]);
const obj = Object.fromEntries(map);
console.log(obj); // { foo: "bar", baz: 42 }
With Object.fromEntries, you can convert from Array to Object:
const arr = [
["0", "a"],
["1", "b"],
["2", "c"],
];
const obj = Object.fromEntries(arr);
console.log(obj); // { 0: "a", 1: "b", 2: "c" }
With Object.fromEntries, its reverse method Object.entries(), and array manipulation methods, you are able to transform objects like this:
const object1 = { a: 1, b: 2, c: 3 };
const object2 = Object.fromEntries(
Object.entries(object1).map(([key, val]) => [key, val * 2]),
);
console.log(object2);
// { a: 2, b: 4, c: 6 }
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-object.fromentries |
Object.fromEntries in core-jsObject.fromEntriesObject.entries()Object.keys()Object.values()Object.prototype.propertyIsEnumerable()Object.create()Map.prototype.entries()Map.prototype.keys()Map.prototype.values()This page was last modified on Oct 30, 2025 by MDN contributors.
Objectassign()create()defineProperties()defineProperty()entries()freeze()fromEntries()getOwnPropertyDescriptor()getOwnPropertyDescriptors()getOwnPropertyNames()getOwnPropertySymbols()getPrototypeOf()groupBy()hasOwn()is()isExtensible()isFrozen()isSealed()keys()preventExtensions()seal()setPrototypeOf()values()Object/FunctionYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |