JavaScript (ES2026) reference · Object Methods
JavaScript Object.fromEntries() Method
Build an object from an iterable of [key, value] pairs, such as an array or a Map. The opposite of Object.entries().
JavaScript (ES2026) Since ES2019
Syntax
Object.fromEntries(iterable)
Parameters
| Parameter | Description |
|---|---|
iterable |
Pairs such as [["a", 1]] or a Map. |
Return value
A new object.
Examples
console.log(Object.fromEntries([["a", 1], ["b", 2]]));
console.log(Object.fromEntries(new Map([["x", true]])));
Output
{ a: 1, b: 2 }
{ x: true }const prices = { tea: 3, cake: 4 };
const withTax = Object.fromEntries(Object.entries(prices).map(([k, v]) => [k, Math.round(v * 1.2 * 100) / 100]));
console.log(withTax);
Output
{ tea: 3.6, cake: 4.8 }Version history
| Version | Change |
|---|---|
| JavaScript ES2019 | Added |
In other languages
dict()· Pythonarray_combine()· PHP
Related
Object.entries()· Return an array of an object's own enumerable [key, value] pairs, ready for for…of loops or array methods.Object.groupBy()· Group the items of an iterable into an object whose keys come from a callback, e.g. orders grouped by status.- JavaScript Objects · tutorial