Filter Operator in Angular Observable

The Filter Operator in Angular filters the items emitted by the source Observable by using a condition (predicate). It emits only those values, which satisfies the condition and ignores the rest.

Filter in Angular

Filter is the simplest and most used RxJs Operator in Angular. The Filter Operator takes 2 arguments.

Syntax

The first argument is the predicate function. This function is evaluated against each value of the source observable. Filter emits only those values which satisfies the the predicate. The predicate function takes 2 parameters. The first one is the value emitted by the source. The second argument is zero based index

The second argument thisArg is Optional. It determines the value of this in the predicate function

Filter Example

The following example filter function returns true only if the value is an even number.

Source Code

Filter Empty or undefined

Filter object or array

Source Code

Reference

Filter

Read More

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top