Set.prototype[@@iterator]()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015ë 9ì.
Set ê°ì²´ì @@iterator ë©ìëë
Iteration íë¡í ì½ì 구ííë©°,
ì ê° êµ¬ë¬¸ ë°
for...of 루íì ê°ì´
ìí를 ììíë ëë¶ë¶ì 구문ìì Setì ì¬ì©í ì ìëë¡ í©ëë¤. Setì ê°ì ì°ì¶íë ë°ë³µì를 ë°íí©ëë¤.
ì´ ìì±ì ì´ê¸° ê°ì Set.prototype.values ìì±ì ì´ê¸° ê°ê³¼ ëì¼í í¨ì ê°ì²´ì
ëë¤.
ìëí´ ë³´ê¸°
const set1 = new Set();
set1.add(42);
set1.add("forty two");
const iterator1 = set1[Symbol.iterator]();
console.log(iterator1.next().value);
// Expected output: 42
console.log(iterator1.next().value);
// Expected output: "forty two"
구문
set[Symbol.iterator]()
ë°í ê°
Set.prototype.values()ì ëì¼íê² setì ê°ì ì°ì¶íë ìë¡ì´ ë°ë³µ ê°ë¥í ë°ë³µì ê°ì²´ë¥¼ ë°íí©ëë¤.
ìì
>for...of 루í를 ì¬ì©í ë°ë³µ
ì´ ë©ìë를 ì§ì í¸ì¶í íìë ê±°ì ììµëë¤. @@iterator ë©ìëì ì¡´ì¬ë Set ê°ì²´ê°
ë°ë³µ ê°ë¥íê² í´ì£¼ë©°,
for...of 루íì ê°ì ë°ë³µ 구문ì ì´ ë©ìë를 ìëì¼ë¡ í¸ì¶íì¬ ë£¨í를 ë릴 ë°ë³µì를 ì»ê² ë©ëë¤.
const mySet = new Set();
mySet.add("0");
mySet.add(1);
mySet.add({});
for (const v of mySet) {
console.log(v);
}
ë°ë³µì ìëì¼ë¡ ë리기
ë°íë ë°ë³µì ê°ì²´ì next() ë©ìë를 ìëì¼ë¡ í¸ì¶íì¬ ë°ë³µ íë¡ì¸ì¤ë¥¼ ìµëí ì ì´í ì ììµëë¤.
const mySet = new Set();
mySet.add("0");
mySet.add(1);
mySet.add({});
const setIter = mySet[Symbol.iterator]();
console.log(setIter.next().value); // "0"
console.log(setIter.next().value); // 1
console.log(setIter.next().value); // Object
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2027 Language Specification > # sec-set.prototype-%symbol.iterator% > |