Search⌘ K

Generators and Iterators

Explore how generators and iterators function in ES6 to manage dynamic data. Understand iterable objects with Symbol.iterator methods and how generator functions create iterables that can be used in for-of loops, spread operators, and more.

We'll cover the following...

Recall our string iterator example to refresh what iterable objects and iterators are:

Node.js
let message = 'ok';
let stringIterator = message[Symbol.iterator]();

We call the next method of stringIterator to get the next element:

Node.js
console.log( stringIterator.next() );

However, before we learned about iterators, we used the ...