Loading...
const names = [...users.values()]
.filter((u) => u.active)
.map((u) => u.name);const names = users.values()
.filter((u) => u.active)
.map((u) => u.name)
.toArray();Calling toArray() last keeps filter() and map() lazy, so one array is created instead of three.
toArray() too early and losing the benefit of lazy processing.toArray() is called only on finite iterators or after take().filter() and map() on the iterator.toArray() the same as Array.from(iterator)?For a finite iterator the result is the same array. toArray() reads better at the end of a helper chain.
toArray() work with async iterators?No. Iterator helpers are synchronous; use Array.fromAsync() to collect an async iterator.