how to combine results after rxjs from?

Viewed 27

I want to start with a rxjs from([1,2,3,4,5]) and then map over each and increment by one but then end up with a combined array by the time I subscribe. Ie: [2,3,4,5,6]

here is my attempt

from([1,2,3,4,5]).pipe(
  map(item => item + 1),
  concatMap(el => of(el))
).subscribe(res => console.log("res", res)) // want to print [2,3,4,5,6]
1 Answers

You're close! You can use the toArray operator.

from([1,2,3,4]).pipe(
  map(v => v + 1),
  toArray()
).subscribe(console.log);
Related