RxJS Max() Mathematical Operator
The RxJS max() operator is a mathematical operator that takes in an observable with all values and returns an observable with the maximum value. It takes in a compare function as an argument, which is optional.
Syntax:
Following is the syntax of the max() operator:
Parameter Explanation
comparer_func: It is used to filter the values to consider only the source observable’s max value. It is optional. If it is not provided, the count() operator will consider the default function.
Return value
The return value of the max() operator is observable that provide the max value.
Let us see some examples of max() operator to understand it clearly.
Example 1
Output:
After executing the above example, you will see the following result:
Example 2
Example of the max() operator with comparer functions:
Output:
After executing the above example, you will see the following result:
Here we have used arrays and the values inside the array are compared using the function given in max() operator. After that the max value from the array is returned as output.