Sunday, January 12, 2020

Iterator

Excerpt from https://davidwalsh.name/es6-generators

Iterators are a special kind of behavior, a design pattern actually, where we step through an ordered set of values one at a time by calling next(). Imagine for example using an iterator on an array that has five values in it: [1,2,3,4,5]. The first next() call would return 1, the second next() call would return 2, and so on. After all values had been returned, next() would return null or false or otherwise signal to you that you've iterated over all the values in the data container.

No comments:

Post a Comment

Followers

Blog Archive