Is there a way in RxJS to split an Observable of an array to an array of Observables, one per element?
Use rxjs map
operator to access the inner observable, then use the array operation map
to convert each value to an observable using of
.
import './style.css';
import { rx, of, expand, tap, map } from 'rxjs';
// observable of an array
of([1, 2, 3, 4])
.pipe(map((nums: any) => nums.map((num: any) => of(num))))
.subscribe((nums: any) => {
// output is an array of observables. One for each element.
console.log(nums);
});