RxJS filter() Filtering OperatorRxJS filter() operator is a filtering operator used to filter items emitted by the source observable according to the predicate function. It only emits those values that satisfy a specified predicate. The RxJS filter() operator is like the well-known Array Array .prototype.filter() method. This operator takes values from the source Observable, passes them through a predicate function and only emits those values that get TRUE. Syntax:Following is the syntax of the RxJS filter() operator: Or Parameter Explanation
Return valueThe RxJS filter() operator's return value is observable of values from the source observable satisfied by the predicate function. Let us see some examples of the RxJS filter() operator to understand it clearly. Example 1 (Filter for even numbers)Output: After executing the above example, you will see the following result as array: In the above example, you can see that we have filtered the even numbers using the filter() operator. Example 2 (Filter objects according to their property)Output: After executing the above example, you will see the following result as array: Here, you can see that the RxJS filter() operator has emitted peoples only under the age of 25. Example 3 (Filter numbers greater than a specified value after an interval)Output: After executing the above example, you will see the following result as ArrayArray: In the above example, you can see that the RxJS filter() operator has filtered out all values until the interval is greater than 3.
Next TopicRxJS Operators
|