RxJS map() Transformation OperatorRxJS map() operator is a transformation operator used to transform the items emitted by an Observable by applying a function to each item. It applies a given project function to each value emitted by the source Observable and then emits the resulting values as an Observable. In other words, you can say that the map(0 operator passes each source value through a transformation function to get corresponding values as output. Syntax:Following is the syntax of the map() operator: or Parameter Explanationproject: This specifies a function that is applied to all the values of the source observable. The index parameter is the number i for the i-th emission that has happened since the subscription, starting from the number 0. thisArg: This is an optional argument. Its default value is undefined. Return valueThe map() operator's return value is observable that emits the values from the source Observable transformed by the given project function. Let us see some examples of map() operator to understand it clearly. Example 1 (Add 20 to each number)Output: After executing the above example, you will see the following result as array: In the above example, you can see that each value is emitted by the source Observable by adding a specified number 20. Example 2 (Map to single property)Output: After executing the above example, you will see the following result as array: In the above example, we have used to map a single property only. Here in the example, there are two properties but we have used only "name" to fetch the output.
Next TopicRxJS Operators
|