Set.prototype.entries()

entries() 메소드는 Set 객체의 각각의 요소를 삽입순서대로 [값, 값]의 형태로 가진 배열의 새로운 Iterator 객체를 반환합니다. Set객체에는 Map객체의 key가 없습니다. 그러나, Map 객체의 API와 비슷하게 유지하기 위해, 각각의 "요소"는 "키"와 "값" 자리에 같은 값을 가지게 됩니다. 결과적으로 [값, 값] 형태의 배열이 반환되게 됩니다.

시도해보기

구문

js
entries();

반환 값

주어진 Set의 요소를 삽입순서대로 [값, 값]의 형태로 포함한 배열의 새로운 iterator 객체를 반환합니다.

예제

entries() 사용하기

js
var mySet = new Set();
mySet.add("foobar");
mySet.add(1);
mySet.add("baz");

var setIter = mySet.entries();

console.log(setIter.next().value); // ["foobar", "foobar"]
console.log(setIter.next().value); // [1, 1]
console.log(setIter.next().value); // ["baz", "baz"]

명세

Specification
ECMAScript Language Specification
# sec-set.prototype.entries

브라우저 호환성

BCD tables only load in the browser

같이 보기