filter
Last updated
Last updated
filter(select: Function, thisArg: any): Observable
π‘ If you would like to complete an observable when a condition fails, check out !
filter
?This operator is your go-to when you need to sift out unwanted values from an observable stream. Think of it as a fisherman's net, catching only the types of fish you desire while allowing others to slip through.
The critical point to remember is that filter
will only emit values that meet the specified condition. If no values in the observable satisfy the condition, nothing gets emitted. It's a strict bouncer at a club's entrance, only letting in those who fit the criteria.
Also, for scenarios where you not only want to filter values but also transform them, is an ideal companion to filter
. Use them in tandem to both shape and refine your data streams.
Example 1: filter for even numbers
( | | )
Example 2: filter objects based on property
Example 3: filter for number greater than specified value
( | | )
( | | )
π° - Official docs
- In Depth Dev Reference
π₯ π΅ - John Linquist
π₯ π΅ - AndrΓ© Staltz
π₯ - Kwinten Pisman
π Source Code: