masterach
masterach

Reputation: 447

How do I return an array from Rxjs subscribe method?

I have this code:

Rx.Observable.from([1,2,3,4,5,6])
.subscribe(x=>console.log(x));

How can I return an array from subscribe instead of the subscribe iterating through the array elements from the .from() method?

I want the x argument to be an array and to console.log() this array.

Upvotes: 1

Views: 868

Answers (2)

Tom Clay
Tom Clay

Reputation: 1

Or, pass it like this:

Rx.Observable.from([[1,2,3,4,5,6]]);

an array whose first element is an array.

Upvotes: 0

Joel
Joel

Reputation: 2404

ReactiveX has the "to" operator, which can be used with RxJS as toArray:

http://reactivex.io/documentation/operators/to.html

Rx.Observable.from([1,2,3,4,5,6])
    .toArray()
    .subscribe(x=>console.log(x));

Upvotes: 1

Related Questions