JavaScript Iterator Object
Iterator is the base of every built-in iterator, such as those returned by array.values() or map.entries(). Its helper methods, like map(), filter() and take(), work lazily on any iterator.
Description
An iterator is an object with a next() method that returns { value, done } results one at a time. Arrays, strings, maps, sets and generators all produce iterators, which is how for...of, spread syntax and destructuring read them. The global Iterator is the shared parent of all built-in iterators.
Iterator helpers, available in current browsers, add methods such as map(), filter(), take(), drop(), flatMap(), reduce(), some(), every(), find() and toArray(). Unlike their array equivalents, they are lazy: values are processed only as they are requested, so they work with very large or infinite sequences. Iterator.from() wraps any iterable or iterator-like object.
You can write your own iterator by giving an object a [Symbol.iterator]() method that returns an object with next(), although generator functions are usually the easiest way. Iterators can only be consumed once: after a loop has read all its values, an iterator is exhausted, while an iterable such as an array can create a fresh iterator each time it's looped over.
Creating
Iterator.from(iterable)Example
Browser Support
The following information will show you the current browser support for the Iterator object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





