© Raju Gandhi 2019
R. GandhiJavaScript Nexthttps://doi.org/10.1007/978-1-4842-5394-6_9

9. Iterable Sequences with Generators and Iterators

Raju Gandhi1 
(1)
Columbus, OH, USA
 

Storing and manipulating data in collections in JavaScript is not only easy, but also elegant. However, iterating is another matter. Consider arrays. In order to iterate and fetch the elements of an array, we use contrived syntax like the for (let i = 0; i < array.length; i++) loop, or even worse, the for-in loop. But that’s not the end of it! Every so often we will have custom objects that might need iteration. We concede defeat, and build (or consume) a custom API (think array.forEach) just so we can get each element in a particular sequence.

Well those days are over.

ES6 introduces ...

Get JavaScript Next: Your Complete Guide to the New Features Introduced in JavaScript, Starting from ES6 to ES9 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.