O'Reilly logo

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond by JD Isaacks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required