Unit 5. Iterables

In JavaScript, Strings and Arrays have always had a couple of things in common. They both contain an indefinite amount of stuff—characters in the case of strings and any datatype in the case of arrays. They both also have a length property indicating how many items they have. But there was never a common protocol that described how these things worked. Starting in ES2015, there are two new protocols that describe these JavaScript behaviors, known as the iterable and iterator protocols.

Strings and Arrays are now known as iterables. This means they adhere to the new iterable protocol and can be predictably interacted with in common ways, including being used with the new for..of statement and the new spread operator. There ...

Get Get Programming with JavaScript Next now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.