[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries [Back]  [Original]

Object.fromEntries() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Object.fromEntries()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2020 1.

Object.fromEntries() .

In this article

const entries = new Map([
  ["foo", "bar"],
  ["baz", 42],
]);

const obj = Object.fromEntries(entries);

console.log(obj);
// Expected output: Object { foo: "bar", baz: 42 }

js
Object.fromEntries(iterable);

iterable

. , Array, Map .

.

Object.fromEntries() , . iterable @@iterator , 2 . , .

Object.fromEntries()Object.entries() .

Map Object

js
const map = new Map([
  ["foo", "bar"],
  ["baz", 42],
]);
const obj = Object.fromEntries(map);
console.log(obj); // { foo: "bar", baz: 42 }

Array Object

js
const arr = [
  ["0", "a"],
  ["1", "b"],
  ["2", "c"],
];
const obj = Object.fromEntries(arr);
console.log(obj); // { 0: "a", 1: "b", 2: "c" }

Object.fromEntries() Object.entries(), .

js
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


Web Proxy Viewer  |  New URL  |  Original Page