liveBook · Manning

Iterable protocol

The iterable protocol is the JavaScript protocol by which an object provides a method keyed by Symbol.iterator that returns an iterator.

How 2 Manning books explain it

The Joy of JavaScript

Symbol.iterator is a built-in JavaScript symbol that defines the method an object uses to provide its iterator.

How it is used
Customizes how objects participate in for...of loops, spread expressions, and destructuring.
How deep it goes
Defines Symbol.iterator, iterator results, delegation, and generators, while deferring detailed generator and asynchronous treatment.
Examples
Uses strings, Blockchain, Block, Transaction, Pair, and Validation to demonstrate delegation, termination, generators, and destructuring.
What you can do after
Apply it via JavaScript to build custom objects that work with standard iteration syntax and composable data-processing patterns.

Read how The Joy of JavaScript explains iterable protocol →

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

The well-known property name that an iterable object exposes to supply an iterator in JavaScript.

How it is used
Enables objects to supply values to `for...of` and spread through a common protocol.
How deep it goes
Explains the `Symbol.iterator` method, `next()` results, and completion, then demonstrates manual and generator-based implementations.
Examples
Uses array indices versus values, a three-prime iterable, a customized string iterator, and a bounded-iteration exercise.
What you can do after
Build it from scratch by supplying `Symbol.iterator`, or customize an existing iterable’s yielded values.

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

Related concepts

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.