Learn RxJS
Search…
toArray

signature: toArray(): OperatorFunction

Collects all source emissions and emits them as an array when the source completes.

Examples

Example 1: get values emitted by interval as an array when interval completes
1
// RxJS v6+
2
import { interval } from 'rxjs';
3
import { toArray, take } from 'rxjs/operators';
4
5
interval(100)
6
.pipe(take(10), toArray())
7
.subscribe(console.log);
8
9
// output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Copied!

Additional Resources

Last modified 2yr ago