liveBook · Manning

For...of

The JavaScript for...of statement iterates over successive values produced by an iterable's iterator.

How 3 Manning books explain it

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.

Read how Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond explains for...of →

What to know first

Related concepts

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.