Get to know MDN better
Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The toArray() method of Iterator instances creates a new Array instance populated with the elements yielded from the iterator.
None.
A new Array instance containing the elements from the iterator in the order they were produced.
iterator.toArray() is equivalent to Array.from(iterator) and [...iterator], except that it's easier to chain when multiple iterator helper methods are involved. The following example creates an iterator that yields terms in the Fibonacci sequence, takes the first 10 terms, filters out the odd numbers, and converts the result to an array:
Note that it's a good idea to call toArray() as a last step of your processing. For example, fibonacci().take(10).toArray().filter(...) is less efficient, because iterator helpers are lazy and avoids creating a temporary array.
| ECMAScript® 2027 Language Specification # sec-iterator.prototype.toarray |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.