[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Errors/is_not_iterable [Back]  [Original]

TypeError: 'x' is not iterable - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

TypeError: 'x' is not iterable

    TypeError: 'x' is not iterable (Firefox, Chrome)
    TypeError: 'x' is not a function or its return value is not iterable (Chrome)

In this article

TypeError

?

Promise.all TypedArray.from forof right hand-side iterable . iterable Array, String Map, , iterable protocol iterable .

iterating

JavaScript iterable protocol Object iterable . , forof .

js
var obj = { France: "Paris", England: "London" };
for (let p of obj) {
  // TypeError: obj is not iterable
  // 
}

Object.keys Object.entries .

js
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 .

js
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 .

js
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 .

js
function* generate(a, b) {
  yield a;
  yield b;
}

for (let x of generate(1, 2)) console.log(x);


Web Proxy Viewer  |  New URL  |  Original Page