JavaScript Iterator : Iterable
An Iterator is an Object that returns a sequence of values. Since Iterators are Iterables, you can use
for (var value of iterator) {}
to easily loop over the values in an iterator. Calling an ECMAScript 2015 generator function (function*() {}
) returns an Iterator. You may create your own Iterable object by assigning the Symbol.iterator
property to an object with a next()
method.Copyright © JavaScripture Contributors