Object.fromEntries()

Object.fromEntries(iterable)
Returns: Object · Updated March 13, 2026 · Object Methods
object transformation es2019

Object.fromEntries() transforms an iterable of key-value pairs into an object. This method is the inverse of Object.entries() and provides a convenient way to convert Maps, Arrays, or any iterable yielding two-element arrays into a plain object.

Syntax

Object.fromEntries(iterable)

Parameters

ParameterTypeDescription
iterableArray or MapAn iterable yielding key-value pairs like [[key, value], …] or a Map

Examples

Converting an array of pairs

const pairs = [["name", "Alice"], ["age", 30], ["city", "NYC"]];
const obj = Object.fromEntries(pairs);

console.log(obj);
// { name: "Alice", age: 30, city: "NYC" }

Converting a Map to an object

const map = new Map([
  ["framework", "React"],
  ["version", "18"],
  ["type", "library"]
]);

const obj = Object.fromEntries(map);

console.log(obj);
// { framework: "React", version: "18", type: "library" }

URL search params to object

const params = new URLSearchParams("name=John&age=25&city=Boston");
const obj = Object.fromEntries(params);

console.log(obj);
// { name: "John", age: "25", city: "Boston" }

Transforming object values

const prices = { apple: 10, banana: 20, orange: 15 };

const doubled = Object.fromEntries(
  Object.entries(prices).map(([key, value]) => [key, value * 2])
);

console.log(doubled);
// { apple: 20, banana: 40, orange: 30 }

Common Patterns

Filtering object properties

const user = { name: "Alice", age: 30, password: "secret123", token: "abc" };

// Remove sensitive fields
const safe = Object.fromEntries(
  Object.entries(user).filter(([key]) => !["password", "token"].includes(key))
);

console.log(safe);
// { name: "Alice", age: 30 }

Converting query string to object

function parseQuery(queryString) {
  const params = new URLSearchParams(queryString.slice(1));
  return Object.fromEntries(params);
}

const result = parseQuery("?sort=asc&limit=10&offset=20");
console.log(result);
// { sort: "asc", limit: "10", offset: "20" }

Object to Map and back

const obj = { a: 1, b: 2 };
const map = new Map(Object.entries(obj));

map.set("c", 3);
const backToObj = Object.fromEntries(map);

console.log(backToObj);
// { a: 1, b: 2, c: 3 }

See Also

  • Object.entries() — Returns an array of key-value pairs from an object (inverse of fromEntries)
  • Object.keys() — Returns an array of object keys, commonly used with fromEntries for transformations