JavaScript TypeError – ‘X’ is not iterable

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.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output(in console):

TypeError: GFG_Obj is not iterable

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

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output(in console):

TypeError: GFG is not iterable

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.