8ITERATORS AND GENERATORS

image

Many programming languages have shifted from iterating over data with for loops, which requires initializing variables to track position in a collection, to using iterator objects that programmatically return the next item in a collection. Iterators make working with collections of data easier, and ECMAScript 6 adds iterators to JavaScript. When coupled with new array methods and new types of collections (such as sets and maps), iterators are essential for efficient data processing and you’ll find them in many parts of the language. The new for-of loop works with iterators; the spread operator (...) uses iterators; and ...

Get Understanding ECMAScript 6 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.