The mapTo
operator is used to map each value emitted by the source Observable to a static value, producing a new Observable that emits the mapped value instead of the original value. Here's how to use it with RxJS:
index.tsx418 chars12 lines
In this example, we create an Observable source
that emits the numbers 1 through 5. We then use the mapTo
operator to map each value emitted by source
to the string 'Hello World!'
, producing a new Observable example
. Finally, we subscribe to example
and log each value emitted to the console, which will output the string 'Hello World!'
five times.
gistlibby LogSnag