toArray
Recoge todas las emisiones del Observable fuente y las emite en un array cuando este se complete
Last updated
import { fromEvent } from "rxjs";
import { map, take, toArray } from "rxjs/operators";
const key$ = fromEvent<KeyboardEvent>(document, "keydown");
key$
.pipe(
take(4),
map(({ code }) => code),
toArray()
)
.subscribe(console.log);
// Salida: [ 'KeyR', 'KeyX', 'KeyJ', 'KeyS' ]import { interval } from "rxjs";
import { toArray, take } from "rxjs/operators";
const source = interval(1000);
const example = source.pipe(take(10), toArray());
const subscribe = example.subscribe((val) => console.log(val));
// Salida: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]