From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../global_objects/object/fromentries/index.html | 98 ++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 files/ko/web/javascript/reference/global_objects/object/fromentries/index.html (limited to 'files/ko/web/javascript/reference/global_objects/object/fromentries/index.html') diff --git a/files/ko/web/javascript/reference/global_objects/object/fromentries/index.html b/files/ko/web/javascript/reference/global_objects/object/fromentries/index.html new file mode 100644 index 0000000000..4d74fc326a --- /dev/null +++ b/files/ko/web/javascript/reference/global_objects/object/fromentries/index.html @@ -0,0 +1,98 @@ +--- +title: Object.fromEntries() +slug: Web/JavaScript/Reference/Global_Objects/Object/fromEntries +tags: + - JavaScript + - Method + - Object + - Reference +translation_of: Web/JavaScript/Reference/Global_Objects/Object/fromEntries +--- +
{{JSRef}}
+ +

Object.fromEntries() 메서드는 키값 쌍의 목록을 객체로 바꿉니다.

+ +
{{EmbedInteractiveExample("pages/js/object-fromentries.html")}}
+ +

구문

+ +
Object.fromEntries(iterable);
+ +

매개변수

+ +
+
iterable
+
반복 가능한 객체. 즉, {{jsxref("Array")}}, {{jsxref("Map")}} 또는 반복 규약을 구현한 기타 객체.
+
+ +

반환 값

+ +

속성의 키와 값을 반복 가능한 객체에서 가져온 새로운 객체.

+ +

설명

+ +

Object.fromEntries() 메서드는 키값 쌍 목록을 받고, 그 목록을 사용해 속성을 부여한 새로운 객체를 반환합니다. iterable 인자는 @@iterator 메서드를 구현하여 반복기 객체를 반환해야 하고, 그 반복기는 또 배열 형태의 객체로 요소 2개를 반환해야 합니다. 반환된 요소 중 첫 번째는 생성할 객체의 속성 키로, 두 번째는 속성 값으로 사용합니다.

+ +

Object.fromEntries()는{{jsxref("Object.entries()")}}의 역을 수행합니다.

+ +

예제

+ +

Map에서 Object

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

Array에서 Object

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

객체 변환

+ +

Object.fromEntries()와 그 역인 {{jsxref("Object.entries()")}}, 그리고 배열 변형 메서드를 통해 객체를 변환할 수 있습니다.

+ +
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 }
+ +

명세

+ + + + + + + + + + + + + + +
SpecificationStatus
https://tc39.github.io/proposal-object-from-entriesStage 3
+ +

브라우저 호환성

+ +

{{Compat("javascript.builtins.Object.fromEntries")}}

+ +

같이 보기

+ + -- cgit v1.2.3-54-g00ecf