Get to know MDN better
The JavaScript exception "is not iterable" occurs when the value which is spread into an array or function call, given as the right-hand side of for...of, as argument of a function such as Promise.all or Set(), or as the right-hand side of an array destructuring, is not an iterable object. This error is also encountered when Array.fromAsync() or for await...of is used with a non-async iterable.
The value which is spread into an array or function call, given as the right-hand side of for...of, or as argument of a function such as Promise.all or Set(), or as the source of an array destructuring pattern, is not an iterable object. An iterable can be a built-in iterable type such as Array, String or Map, a generator result, or an object implementing the iterable protocol.
The non-iterable might turn to be undefined in some runtime environments.
In JavaScript, Objects are not iterable unless they implement the iterable protocol. Therefore, you cannot use for...of to iterate over the properties of an object.
Instead you have to use Object.keys or Object.entries, to iterate over the properties or entries of an object.
Another option for this use case might be to use a Map:
Generator functions are functions you call to produce an iterable object.
When they are not called, the Function object corresponding to the generator is callable, but not iterable. Calling a generator produces an iterable object which will iterate over the values yielded during the execution of the generator.
Custom iterables can be created by implementing the Symbol.iterator method. You must be certain that your iterator method returns an object which is an iterator, which is to say it must have a next method.
Here is a correct implementation:
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.