I have an observable that emits an array of objects. What pipe able operators do I need to use to transform it to an Observable so I can act on each object?
What do I need to do to obs$ to make it emit like obs2$ ?
const obs$ = of([{ opponent: 'Walton', team: 'varsity', gametime: new Date() },
{ opponent: 'Scott', team: 'varsity', gametime: new Date() },
{ opponent: 'Dixie', team: 'varsity', gametime: new Date() },
{ opponent: 'Highlands', team: 'freshmen', gametime: new Date() }])
.pipe(
tap(console.log)
);
obs$.subscribe(a =>
console.log(a)
);
const obs2$ = of({ opponent: 'Walton', team: 'varsity', gametime: new Date() },
{ opponent: 'Scott', team: 'varsity', gametime: new Date() },
{ opponent: 'Dixie', team: 'varsity', gametime: new Date() },
{ opponent: 'Highlands', team: 'freshmen', gametime: new Date() })
.pipe(
tap(console.log)
);
obs2$.subscribe(a =>
console.log(a)
);
You need mergeAll
:
of([2, 3, 4]).pipe(
mergeAll()
).subscribe(v => console.log(v));
// outputs 2, 3, 4
If you use from
it will work too:
from([2, 3, 4])
.subscribe(v => console.log(v));
// outputs 2, 3, 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With