Iterables & Iterators
Learn what an iterable is and what it does. Learn how the spread operator and for-of loops work under the hood and how to take advantage of them.
ES2015 introduced the iterable protocol. This is a way for objects to describe how they should behave when under iteration, or when we are trying to access their elements.
Has a property method, the key for which is
Symbol.iterator. The method should:
Return an iterator. An iterator is an object with a
nextmethod. An iterator’s
nextmethod should return an object that has the following properties:
value, any type
done, a Boolean
Let’s build up an iterable using these rules.