Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

RxJS mapTo() Transformation Operator

RxJS mapTo() operator is a transformation operator that emits a constant value as an output along with the Observable whenever the source Observable emits a value.

Like a map() operator, it maps every source value to the same output value every time.

Syntax:

Following is the syntax of the mapTo() operator:

Parameter Explanation

value: It specifies a value as an argument which is mapped to the source value given.

Return value

The mapTo() operator's return value is Observable that emits the given value every time the source Observable emits something.

Let us see some examples of mapTo() operator to understand it clearly.

Example 1 (Map every emission to String)

Output:

After executing the above example, you will see the following result as array:

RxJS mapTo() Transformation Operator

In the above example, you can see that every value is mapped to string which is emitted after three seconds.

Example 2 (Mapping clicks to string)

Output:

After executing the above example, you will see the following result as array:

RxJS mapTo() Transformation Operator

In the above example, you can see that it has mapped every click to the string 'Hello World....Welcome to JavaTpoint!' which is displayed on the console as output.


Next TopicRxJS Operators





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA