TypeError: 'x' is not iterable (Firefox, Chrome) TypeError: 'x' is not a function or its return value is not iterable (Chrome)ìë¬ íì 무ìì´ ë¬¸ì ì¸ê°ì?
Promise.all
ëë TypedArray.from
ê³¼ ê°ì í¨ìì ìê·ë¨¼í¸ ëë forâ¦of ì right hand-side ë¡ ì£¼ì´ì§ ê°ì´ iterable ê°ì²´ê° ìëëë¤. iterable ì Array
, String
ëë Map
, ìì±ì ê²°ê³¼, ëë iterable protocol 구í ê°ì²´ì ê°ì ë´ì¥ iterable íì
ì´ ë ì ììµëë¤.
JavaScript ìì iterable protocol ì 구ííì§ ìì Object
ë iterable ì´ ìëëë¤. ê·¸ë¬ë¯ë¡, ê°ì²´ì íë¡í¼í°ë¥¼ ë°ë³µí기 ìí´ forâ¦of 를 ì¬ì©íë©´ ìë©ëë¤.
var obj = { France: "Paris", England: "London" };
for (let p of obj) {
// TypeError: obj is not iterable
// â¦
}
ê°ì²´ì 모ë í목 ëë íë¡í¼í°ë¥¼ ë°ë³µíë ¤ë©´ ëì Object.keys
ëë Object.entries
를 ì¬ì©í´ì¼ í©ëë¤.
var obj = { France: "Paris", England: "London" };
// 모ë íë¡í¼í° ì´ë¦ì iterate:
for (let country of Object.keys(obj)) {
var capital = obj[country];
console.log(country, capital);
}
for (const [country, capital] of Object.entries(obj))
console.log(country, capital);
ì´ ì ì¦ ì¼ì´ì¤ì ëí ë¤ë¥¸ ìµì
ì Map
ì ì¬ì©íë ê²ì
ëë¤.
var map = new Map();
map.set("France", "Paris");
map.set("England", "London");
// 모ë íë¡í¼í° ì´ë¦ iterate
for (let country of map.keys()) {
let capital = map[country];
console.log(country, capital);
}
for (let capital of map.values()) console.log(capital);
for (const [country, capital] of map.entries()) console.log(country, capital);
Generator iterating
Generators ë iterable ê°ì²´ë¥¼ ìì±í기 ìí´ í¸ì¶íë í¨ìì ëë¤.
function* generate(a, b) {
yield a;
yield b;
}
for (let x of generate) // TypeError: generate is not iterable
console.log(x);
generator ê° í¸ì¶ëì§ ìì¼ë©´, generator ì í´ë¹íë Function
ê°ì²´ë¥¼ í¸ì¶í ìë ìì§ë§ interable íì§ë ììµëë¤. generator í¸ì¶ì generator ì¤íëì yield ë 모ë ê°ì iterate íë iterable ê°ì²´ë¥¼ ìì±í©ëë¤.
function* generate(a, b) {
yield a;
yield b;
}
for (let x of generate(1, 2)) console.log(x);
í¨ê» 보기
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