← Back to design patterns map
🔁
Design Pattern

Iterator

Traverse a collection without exposing how it is stored.

behavioral

Visual Diagram

Collection
-> iterator.next()
-> item by item

When To Use

  • ->Custom collection traversal
  • ->Paginated API processing
  • ->Lazy file or stream reading
  • ->Generator-based flows
Used in: for...of, async iterators, streams
iterator.js

Live Editor

Loading...

Output

Run code to see output...