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: New features of ECMAScript 2015, 2016, and beyond now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.