skip to content

toArray

 

Combines all stream values into one array, emits this array and immediately completes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const { rxObserver } = require('api/v0.3');
const { timer } = require('rxjs');
const { take, toArray } = require('rxjs/operators');


// create a timer with 3 events
const source$ = timer(0, 5).pipe(
    take(3)
  );

// collapse all events into one array
const result$ = source$.pipe(
    toArray()
  );

source$.subscribe(rxObserver('timer(0, 10).take(4)'));
result$.subscribe(rxObserver('.toArray()'));

0mstimer(0, 10).take(4)startcomplete00 11 22 .toArray()startcomplete[0,1,2][0,1,2]