Open In App

JavaScript TypeError – ‘X’ is not iterable

Last Updated : 22 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This JavaScript exception is not iterable occurs if the value present at the right-hand-side of for…of or as argument of a function such as Promise.all or TypedArray.from, can not be iterated or is not an iterable object.

Message:

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

Error Type:

TypeError

Cause of Error: Somewhere in the code, the value present at the right-hand-side of for…of or as argument of a function such as Promise.all or TypedArray.from, is used like it can be iterated or is an iterable object.

Example 1: In this example, the GFG_Obj is not iterable, So the error has occurred.

Javascript




let GFG_Obj = { 'prop1': 'val1', 'prop2': 'val2' };
// TypeError: GFG_Obj is not iterable
for (let x of GFG_Obj) {
    // Do Anything.
}


Output(in console):

TypeError: GFG_Obj is not iterable

Example 2: In this example, the GFG is not iterable, So the error has occurred.

Javascript




function* GFG(a, b) {
    yield a;
    yield b;
}
// TypeError: GFG is not iterable
for (let y of GFG)
    console.log(x);


Output(in console):

TypeError: GFG is not iterable

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads