Javatpoint Logo
Javatpoint Logo

RxJS Count() Mathematical Operator

The RxJS count() operator is a mathematical operator that takes in an Observable with values and converts it into an Observable that will give a single counted value. It also acts as a function that takes in predicate function as an optional argument. This is a Boolean type function and will add value to the output only if the value is true.

Syntax:

Following is the syntax of count() operator:

Parameter Explanation

predicate_func: It is used to filter the values that are counted from the source observable and return a boolean value. It is optional.

Return value

The count() operator's return value is observable that provides the count of the given numbers.

Let us see some examples of count() operator to understand it clearly.

Example 1

Example of the count() operator without predicate and with function. See the following example:

Output:

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

RxJS Count() Mathematical Operator

In the above example, you can see that the counted values are 8 which is correct.

Example 2

See the example of the count() operator with a predicate function:

Output:

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

RxJS Count() Mathematical Operator

Here, you can see that it has given the count only of even numbers.


Next TopicRxJS Operators




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA