iterator.toArray() reads the iterator until it is done and builds a new Array with those values in order. It is the handy finishing step after a chain of helpers.
Prefer calling it last. Helpers such as map() and filter() stay lazy; collecting too early builds temporary arrays you do not need. It is similar to Array.from(iterator) or [...iterator], but easier to chain.
Remember
iterator.toArray()
pulls every remaining value
returns a new Array
use it LAST after map / filter / take
similar to Array.from(it) or [...it]
empty iterator → []
Syntax
Call toArray() on an iterator when you want a normal array of the remaining values.
JavaScript
const it = [1, 2, 3].values();
const list = it.map((n) => n * 2).toArray();
console.log(list); // [2, 4, 6]
The Try It page first checks that iterator.toArray() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Get an iterator..values() yields the three colour names.
Collect them.toArray() pulls every value into one new array.
Check the type.Array.isArray(list) is true, so normal array methods work.
Example 2 — Finish a Helper Chain
Map and filter first (still lazy), then call toArray() once at the end.
JavaScript
const result = [1, 2, 3, 4, 5].values()
.map((n) => n * 10)
.filter((n) => n >= 30)
.toArray();
console.log(result.join(", "));
The Try It page first checks that iterator.toArray() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Map to tens. Values become 10, 20, 30, 40, 50.
Keep the large ones.filter drops anything below 30.
Collect once.toArray() builds [30, 40, 50] only after the lazy work.
Example 3 — Limit Values Then Collect
Use take() so infinite or long sources stay safe, then finish with toArray().
JavaScript
function* count() {
let n = 1;
while (true) {
yield n;
n += 1;
}
}
const first = count().map((n) => n * n).take(4).toArray();
console.log(first.join(", "));
The Try It page first checks that iterator.toArray() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Infinite source. The generator can yield forever, so you must not call bare toArray() on it.
Map and limit. Squares are mapped lazily, then take(4) stops after four values.
Safe collect.toArray() builds [1, 4, 9, 16] and the loop ends.
Compatibility
Browser & Runtime Support
Iterator.prototype.toArray() is an Iterator helper (Baseline Newly available since March 2025). It works in current browsers and in Node.js 22 or newer.
✓ Baseline 2025 · Newly available
iterator.toArray()
Supported in Chrome 122+, Edge 122+, Firefox 131+, Safari 18.4+, Opera 108+ and Node.js 22+. Internet Explorer never got it.
2025Standard since
Google Chrome122+ · Desktop & Mobile
Full support
Microsoft Edge122+ · Chromium based
Full support
Mozilla Firefox131+ · Desktop & Mobile
Full support
Apple Safari18.4+ · macOS & iOS
Full support
Opera108+ · Chromium based
Full support
Samsung Internet26+ · Android
Supported
Android WebView122+ · Chromium based
Supported
Node.js22+ · Server runtime
Supported
DenoRecent versions · JavaScript runtime
Supported
BunRecent versions · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
iterator.toArray()Current browsers
Bottom line: Check support with a typeof test before you use it in older browsers. Prefer chaining helpers and calling toArray() last.
Frequently Asked Questions
It reads every remaining value from the iterator and returns them in a new Array, in order. An empty or finished iterator returns [].
Call it last, after map, filter, take, drop, and similar helpers. That keeps the chain lazy and avoids building temporary arrays too early.
For a single iterator, yes — you get a new array of its values. toArray() is nicer to chain at the end of Iterator helpers.
Only if you limit it first with take() or stop another way. Otherwise it never finishes pulling values.
It is exhausted. Calling next() again usually returns { done: true }. Start a fresh iterator if you need the values again.