Home » RxJS toArray() Utility Operator

RxJS toArray() Utility Operator

by Online Tutorials Library

RxJS toArray() Utility Operator

RxJS toArray() operator is a utility operator used to collect all the values emitted by the source observable and emits them as an array when the source completes.

In other words, we can say that the RxJS toArray() operator returns all values inside an array as an output when the source completes.

Syntax:

Following is the syntax of the RxJS toArray() utility operator:

Or

Parameter Explanation

It doesn’t use any parameter that we have to explain.

Return value

The RxJS toArray() operator returns an observable that gives the values from the source observable as an array in the form of output when the source is completed.

Let us see an example of the RxJS toArray() operator to understand it clearly.

Example 1 (Get values emitted when source is completed)

Output:

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

RxJS toArray() Utility Operator

Example 2 (Get values emitted by interval as an array when interval is completed)

Output:

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

RxJS toArray() Utility Operator


Next TopicRxJS Operators

You may also like