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.

JavaScript Iterables

In JavaScript, an iterable is an object that has the following qualities:

  • Has a property method, the key for which is Symbol.iterator. The method should:

    • Return an iterator. An iterator is an object with a next method. An iterator’s next method should return an object that has the following properties:

      • value, any type
      • done, a Boolean

Let’s build up an iterable using these rules.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy