JS: Iterator.prototype.toArray
(new in JS: ECMAScript 2025)
iterator.toArray(f)
-
Convert an iterator to array.
Normally you can use this method on any Iterable, because all standard iterable objects are also Iterator.
similar to JS: Array.from
// define a generator function function* gf() { for (let x of [1, 2, 3, 4]) yield x; } // get the first even number console.log( JSON.stringify( gf().toArray(), ) === `[1,2,3,4]`, ); // true
JavaScript. iterator helpers
- JS: Iterator.prototype.map
- JS: Iterator.prototype.forEach
- JS: Iterator.prototype.filter
- JS: Iterator.prototype.reduce
- JS: Iterator.prototype.take
- JS: Iterator.prototype.drop
- JS: Iterator.prototype.every
- JS: Iterator.prototype.some
- JS: Iterator.prototype.find
- JS: Iterator.prototype.flatMap
- JS: Iterator.prototype.toArray