The JavaScript Object.fromEntries() method
The Object.fromEntries() method builds an object from a list of [key, value] pairs. Object.fromEntries([["a", 1], ["b", 2]]) gives {a: 1, b: 2}. It's the inverse of Object.entries(), and together they let you transform an object using array methods.
Overview
Object.fromEntries() turns a list of [key, value] pairs back into an object. It's the exact reverse of Object.entries(), and that pairing is the whole point: entries() breaks an object into an array of pairs, you transform it with array methods, and fromEntries() rebuilds the object.
This unlocks a clean pattern for transforming objects, which otherwise lack map() and filter(). To double every value: Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, v * 2])). To keep only some keys, filter() the entries before rebuilding. It reads like a pipeline once you've seen it a few times.
It also accepts any iterable of pairs, not just an array — so Object.fromEntries(map) converts a Map into a plain object (useful before JSON.stringify(), which ignores Maps), and Object.fromEntries(new URLSearchParams(query)) turns query-string params into an object. The keys become string properties.
Syntax
Object.fromEntries(entries)
Object.fromEntries([["a", 1], ["b", 2]]) // { a: 1, b: 2 }
Object.fromEntries(map) // Map -> object
// transform an object
Object.fromEntries(
Object.entries(obj).map(([k, v]) => [k, v * 2])
)
Parameters
The Object.fromEntries() method accepts the following parameters.
| Parameter | Description |
|---|---|
entries |
An iterable of [key, value] pairs — an array of pairs, a Map, or similar. |
Example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
const prices = { book: 10, pen: 2, lamp: 25 };
// apply a 10% discount to every value
const discounted = Object.fromEntries(
Object.entries(prices).map(([item, price]) => [item, price * 0.9])
);
document.getElementById('out').textContent = JSON.stringify(discounted);
// {"book":9,"pen":1.8,"lamp":22.5}
</script>
Best practices
- Pair it with Object.entries() to transform an object via array methods.
- Convert a Map to a plain object with
Object.fromEntries(map)before stringifying. - Filter entries before rebuilding to pick or drop keys.
- Remember keys become strings — symbol keys aren't preserved.
Frequently asked questions
What does Object.fromEntries() do?
[key, value] pairs — the inverse of Object.entries().How do I transform the values of an object?
Object.fromEntries(Object.entries(obj).map(([k, v]) => [k, transform(v)])).How do I convert a Map to an object?
Object.fromEntries(map), since a Map is an iterable of pairs.How do I filter an object by its keys?
Object.fromEntries(Object.entries(obj).filter(([k]) => keep(k))).