Hiprup

What is Object.fromEntries()?

Object.fromEntries() turns a list of [key, value] pairs into an object — the reverse of Object.entries().

  • Sources — Maps, transformed entries, or URLSearchParams.

  • Pairs with entries() — to map/filter an object then rebuild it.

Use it as a clean way to transform objects functionally.

// From array of pairs
const obj = Object.fromEntries([['a', 1], ['b', 2], ['c', 3]]);
console.log(obj); // { a: 1, b: 2, c: 3 }

// From Map
const map = new Map([['x', 10], ['y', 20]]);
console.log(Object.fromEntries(map)); // { x: 10, y: 20 }

// Transform object values
const prices = { apple: 1.5, banana: 0.75 };
const taxed = Object.fromEntries(
  Object.entries(prices).map(([k, v]) => [k, +(v * 1.1).toFixed(2)])
); // { apple: 1.65, banana: 0.83 }

// From URLSearchParams
const params = new URLSearchParams('?name=John&age=30');
const queryObj = Object.fromEntries(params); // { name: 'John', age: '30' }

fromEntries converts any iterable of [key, value] pairs to a plain object. The transform pipeline (entries → map → fromEntries) modifies object values functionally.

URLSearchParams conversion is a common web development use case. Inverse of Object.entries.

The entries → map → fromEntries pipeline for transforming objects is the key pattern. URLSearchParams conversion is practical.

Know it is the inverse of Object.entries. ES2019.

What is Object.fromEntries()? | Hiprup