RxJS distinct() Filtering OperatorRxJS distinct() operator is a filtering operator that returns all the values from the source Observable that are distinct when compared with the previous values. In the RxJS distinct() operator, if a keySelector function is given, it will project each value from the source observable into a new value that will check for equality with previously projected values. If a keySelector function is not given, it will use each value from the source observable directly with an equality check against previous values. Syntax:Following is the syntax of the distinct() operator: Or Parameter Explanation
Return valueThe RxJS distinct() operator's return value is observable that emits items from the source observable with distinct values. Let us see some examples of distinct() operator to understand it clearly. Example 1 (Distinct Values without Selector)Output: After executing the above example, you will see the following result as array: In the above example, you can see that we have used the repeated values as input but this operator has emitted only the distinct values as output. Example 2 (Distinct values with key selector)Output: After executing the above example, you will see the following result as array:
Next TopicRxJS Operators
|