Stop 04 · JavaScriptTopics · 36/36

Iterators

Part of the Frontend Developer Roadmap

In short

Objects that implement the iterator protocol (`.next()` returning `{value, done}`), the underlying mechanism that makes `for...of` and spread syntax work on arrays, strings, Maps and Sets. The iterator protocol provides a common abstraction for sequential consumption, which is why many built-in collections work with `for...of`, spread, and destructuring.

How to learn this

  1. 1Manually call `.next()` on an array's iterator (`arr[Symbol.iterator]()`). Validate your understanding by applying it in a small practical example.
  2. 2Implement a custom iterable object using `Symbol.iterator`. Validate your understanding by applying it in a small practical example.
  3. 3Understand how generators are a convenient shortcut for writing iterators.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge