A collection is a data structure that contains elements. For example, a string is a collection of characters and an array is a collection of ordered items:

const message = 'Hi!';     // consists of 'H', 'i' and '!'

const numbers = [1, 3, 4]; // consists of 1, 3 and 4

To easily access elements of collections of different structure, JavaScript implements a special pattern named iterator.

In this post, as a part of the iterator pattern, you’ll learn what are iterables and iterators. You’ll also learn about iterables consumers: how to iterate over a collection using for...of cycle, transform any iterable to an array using the spread operator [...iterable], and more.

#javascript #iterator #array

A Simple Explanation of JavaScript Iterators
2.05 GEEK