1

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.

1
  • 3
    Observable.of([...])? .from emits each thing in the iterable as a separate element of the stream. Commented Aug 28, 2017 at 20:14

2 Answers 2

1

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));
Sign up to request clarification or add additional context in comments.

1 Comment

Tnx, this is what I was looking for.
0

Or, pass it like this:

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

an array whose first element is an array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.