Javatpoint Logo
Javatpoint Logo

RxJS find() Conditional Operator

RxJS find() operator is a conditional operator that returns only the first value emitted by the source observable as an output when it meets some specific conditions. It finds the first value that meets some test conditions and emits that.

In other words, we can say that the RxJS find() operator is used to return the observable when the first value of the source observable meets the condition for the predicate function taken as input.

Syntax:

Following is the syntax of the RxJS find() conditional operator:

Or

Parameter Explanation

  • predicate_func: The predicate_func specifies the input given to this operator. It takes the source item and checks if it satisfies the condition given.
  • predicate: It specifies a function which is called with each item to test for condition matching.
  • thisArg: This is an optional argument used to determine its value in the predicate function. Its default value is undefined.

Return value

The RxJS find() operator returns an observable when the first value of the source observable meets with the condition for the predicate function taken as input.

Let us see some examples of the RxJS find() operator to understand it clearly.

Example 1

Output:

After executing the above example, you will see the following result:

RxJS find() Conditional Operator

In the above example, you can see that when it gets the first value satisfying the condition form the following list: list1 = of(11, 22, 33, 44, 55, 66, 77, 88, 99);

Then, it has emitted that value as an output.

Example 2 (Find click inside a box, repeat when the click occurs outside of box)

Output:

After executing the above example, you will see the following result:

RxJS find() Conditional Operator

When you click inside the box, you have got the following output:

RxJS find() Conditional Operator
Next TopicRxJS Operators





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA