Baseline Widely available
Array
ì¸ì¤í´ì¤ì [@@iterator]()
ë©ìëë ìí ê°ë¥ íë¡í ì½ì 구ííë©°, ë°°ì´ì ì ê° êµ¬ë¬¸ì´ë for...of
루íì ê°ì´ ìí ê°ë¥ì 기ëíë ëë¶ë¶ì 구문ìì ì¬ì©í ì ìëë¡ í©ëë¤. ì´ ë©ìëë ë°°ì´ì ê° ì¸ë±ì¤ ê°ì ì°ì¶íë ë°°ì´ ìíì ê°ì²´ë¥¼ ë°íí©ëë¤.
ì´ ìì±ì ì´ê¸° ê°ì Array.prototype.values
ìì±ì ì´ê¸° ê°ê³¼ ëì¼í í¨ì ê°ì²´ì
ëë¤.
const array1 = ["a", "b", "c"];
const iterator1 = array1[Symbol.iterator]();
for (const value of iterator1) {
console.log(value);
}
// Expected output: "a"
// Expected output: "b"
// Expected output: "c"
구문 매ê°ë³ì
ìì.
ë°í ê°Array.prototype.values()
ì ëì¼í ë°í ê°ì
ëë¤. ì´ë ë°°ì´ì ê° ì¸ë±ì¤ì ê°ì ì°ì¶íë ìë¡ì´ ìí ê°ë¥ ìíì ê°ì²´ì
ëë¤.
ì´ ë©ìë를 ì§ì í¸ì¶í íìë ê±°ì ììµëë¤. @@iterator
ë©ìëê° ìì¼ë©´ ë°°ì´ì ìí ê°ë¥ì¼ë¡ ë§ë¤ ì ìì¼ë©°, for...of
루íì ê°ì ìí 구문ì ì´ ë©ìë를 ìëì¼ë¡ í¸ì¶íì¬ ë°ë³µí ìíì를 ì»ìµëë¤.
<ul id="letterResult"></ul>
JavaScript
const arr = ["a", "b", "c"];
const letterResult = document.getElementById("letterResult");
for (const letter of arr) {
const li = document.createElement("li");
li.textContent = letter;
letterResult.appendChild(li);
}
ê²°ê³¼ ìíì를 ìëì¼ë¡ ë¶ë¥´ê¸°
ë°íë ìíì ê°ì²´ì next
ë©ìë를 ìëì¼ë¡ í¸ì¶íì¬ ìí ê³¼ì ì ìµëí ì ì´í ì ììµëë¤.
const arr = ["a", "b", "c", "d", "e"];
const arrIter = arr[Symbol.iterator]();
console.log(arrIter.next().value); // a
console.log(arrIter.next().value); // b
console.log(arrIter.next().value); // c
console.log(arrIter.next().value); // d
console.log(arrIter.next().value); // e
ëì¼í í¨ìë¡ ë¬¸ìì´ê³¼ 문ìì´ ë°°ì´ ì²ë¦¬í기
문ìì´ê³¼ ë°°ì´ì 모ë ìí ê°ë¥ íë¡í ì½ì 구íí기 ë문ì, ë²ì© í¨ìë ë ì
ë ¥ì ëì¼í ë°©ìì¼ë¡ ì²ë¦¬íëë¡ ì¤ê³í ì ììµëë¤. ì´ë ì
ë ¥ì´ ë°°ì´ì´ê±°ë ì ì´ë í´ë¹ ë©ìëê° ìë ê°ì²´ì¬ì¼ íë Array.prototype.values()
를 ì§ì í¸ì¶íë ê²ë³´ë¤ ë«ìµëë¤.
function logIterable(it) {
if (typeof it[Symbol.iterator] !== "function") {
console.log(it, "is not iterable.");
return;
}
for (const letter of it) {
console.log(letter);
}
}
// Array
logIterable(["a", "b", "c"]);
// a
// b
// c
// String
logIterable("abc");
// a
// b
// c
// Number
logIterable(123);
// 123ì ìí ê°ë¥ì´ ìëëë¤.
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4