For...of
The JavaScript for...of statement iterates over successive values produced by an iterable's iterator.
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.
Related concepts
- iteratoruses · An iterator is an object or abstraction that provides successive values from a sequence or data source through a traversal protocol.
- Mapuses · A map is an associative data structure that stores key-value pairs 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 unique elements in which membership is determined by whether an element is present, not by duplicate occurrences.
- loopcontrasts with · A loop is a programming control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
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.

