iterable
An iterable is an object whose values can be stepped through one at a time, for example with a for...of loop or spread syntax, because it has a Symbol.iterator method that returns an iterator.
The iterator does the actual stepping. Each call to its .next() method returns an object with a value and a done flag. Together, the iterable and iterator protocols have been part of JavaScript since ES2015. The key itself is a well-known symbol stored on Symbol.
Strings, arrays, typed arrays, maps, and sets are built-in iterables, because String, Array, Map, and Set define the method on their prototypes. Plain objects don’t, so they aren’t iterable until code adds one.
Iterables are what for...of loops, spread syntax, array destructuring, and yield* consume. Built-in functions such as Array.from(), Promise.all(), and the Map and Set constructors accept any iterable too.
An array hands out a new iterator on every pass. Built-in iterators work differently. They inherit a [Symbol.iterator]() method from Iterator.prototype that returns the iterator itself, so they’re iterables that run out after one pass. Generator objects behave the same way.
An async iterable follows the same pattern with the Symbol.asyncIterator key, and its iterator’s .next() returns a promise. The for await...of loop consumes it.
Example
Say a music app stores a playlist as a plain object and wants to spread its songs into an array:
> const playlist = { songs: ["Intro", "Highway", "Sunset"] };
undefined
> [...playlist]
Uncaught TypeError: playlist is not iterable
> playlist[Symbol.iterator] = function () {
… return this.songs.values();
… };
[Function (anonymous)]
> [...playlist]
[ 'Intro', 'Highway', 'Sunset' ]
> const [opener] = playlist;
undefined
> opener
'Intro'
> new Set(playlist).size
3
Spreading the plain object fails because it has no Symbol.iterator method. Once the method returns an iterator over songs, spread syntax, destructuring, and the Set constructor all accept the playlist, and none of them needs to know how it stores its songs.
Say the app keeps the iterator from .values() to track the songs still to play:
> const songs = ["Intro", "Highway", "Sunset"];
undefined
> const remaining = songs.values();
undefined
> [...songs]
[ 'Intro', 'Highway', 'Sunset' ]
> [...songs]
[ 'Intro', 'Highway', 'Sunset' ]
> [...remaining]
[ 'Intro', 'Highway', 'Sunset' ]
> [...remaining]
[]
> remaining[Symbol.iterator]() === remaining
true
The array yields every song on each spread because each pass gets a new iterator. The remaining iterator returns itself from [Symbol.iterator](), so the second spread continues where the first one stopped and finds nothing left.
Spread the array and step through the iterator in any order to compare a fresh pass with one that runs out:
Related Resources
Course
JavaScript Iterators and Generators for Pythonistas
Port a weather station's sensor feed from Python to JavaScript, and learn to write iterators and function* generators, chain lazy iterator helpers, and read async feeds with for await...of.
For additional information on related topics, take a look at the following resources:
- JavaScript Loops for Pythonistas (Course)
- JavaScript Arrays for Pythonistas (Course)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 19, 2026