Understand Iterators in JavaScript by Building Custom Iterator

In this episode of the hilarious Mattias P Johansson, he discusses JS iterators and builds a custom iterator.

What are Iterators

Iterators are JavaScript objects that know how to access items from a collection one at a time. As processing items in a collection is a very common thing, you have probably used iterators already. When did you use iterators, when you worked with for loops, for ... of, map() and filter(). Behind all those JS is implementing Iterators object for you.

A typical iterator object has next() method which is used to return the next item in the collection with two properties; done and value. These properties indicate if the items in the collections are used up or not, and the value at that point of iteration respectively.

Anyways, why am I boring you when you can watch mpj and learn iterators whilst doing a custom implementation.

Subscribe for coding videos

Keep growing professionally with just three curated videos weekly.

We hate spam as much as you do.