RxJS - Utility Operator toArray

Accumula tutto il valore di origine da Observable e li restituisce come un array quando l'origine è completata.

Sintassi

toArray():Observable

Valore di ritorno

Restituisce un osservabile che restituisce i valori dall'origine osservabile come un array quando l'origine viene completata.

Esempio

import { of} from 'rxjs';
import { toArray } from 'rxjs/operators';

let list1 = of(2, 3, 4, 5, 6);
let final_val = list1.pipe(toArray());
final_val.subscribe(x => console.log(x));

Produzione

[2, 3, 4, 5, 6]