For...of
The JavaScript for...of statement iterates over successive values produced by an iterable's iterator.
Secrets of the JavaScript Ninja, Third Edition
JavaScript loop syntax that retrieves successive values from an iterable.
- How it is used
- Iterates through collection values without managing an index, including arrays and maps.
- How deep it goes
- Explains the Symbol.iterator and next() protocol through direct array traversal, then contrasts practical loop choices.
- Examples
- Shows an array loop, manual array-iterator traversal, a custom iterable, and three ways to loop over a map.
- What you can do after
- Apply it to traverse iterable values, select map entries or keys or values, and avoid confusing for...of with for...in.
Read how Secrets of the JavaScript Ninja, Third Edition explains for...of →
Secrets of the JavaScript Ninja, Second Edition
A JavaScript loop that iterates over iterable values using the iterator protocol.
- How it is used
- Consumes generator-produced sequences without manual iterator control.
- How deep it goes
- Explains next() results through value and done, then characterizes for...of as shorthand for iterator control.
- Examples
- Uses WeaponGenerator to yield weapons and a warrior generator that delegates to a ninja generator.
- What you can do after
- Apply it to consume values yielded by a generator without writing iterator-control code.
Read how Secrets of the JavaScript Ninja, Second Edition explains for...of →
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
A JavaScript looping statement that iterates over iterable values by repeatedly obtaining successive items from an iterator.
- How it is used
- Processes iterable values one at a time, including values in arrays, strings, Sets, and Maps.
- How deep it goes
- Defines value iteration, compares it with for...in and forEach, and demonstrates early exit and generator use without detailing iterator internals.
- Examples
- Contrasts object-key and array-value loops, then uses nested loops to create a card deck from suits and faces.
- What you can do after
- Apply it to process iterable values, stop early with break, or yield values from a generator loop.
What to know first
- iterableAn iterable is an object or value that provides or supports a protocol for producing its elements sequentially.
- MapA map is an associative data structure that stores key-value associations and supports retrieving values by key.
- setA set is a collection of distinct elements in which membership, rather than order or duplicate occurrences, defines the collection.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
Related concepts
- iteratoruses · An iterator is an object or abstraction that provides successive values from a collection or other data source through a traversal interface.
- Mapuses · A map is an associative data structure that stores key-value associations and supports retrieving values by key.
- iterableuses · An iterable is an object or value that provides or supports a protocol for producing its elements sequentially.
- setuses · A set is a collection of distinct elements in which membership, rather than order or duplicate occurrences, defines the collection.
- loopcontrasts with · A loop is a programming-language control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
Questions about for...of
What is for...of?
The JavaScript for...of statement iterates over successive values produced by an iterable's iterator.
Which Manning books explain for...of?
Secrets of the JavaScript Ninja, Third Edition, Secrets of the JavaScript Ninja, Second Edition and Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond.
What should I know before learning for...of?
Manning books that teach for...of usually introduce iterable, Map, set and array first.
What is the difference between for...of and for...in?
The JavaScript for...of statement iterates over successive values produced by an iterable's iterator. The JavaScript for...in statement iterates over an object's enumerable property names, including inherited enumerable properties.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


