O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the concat() operator

The most common operator to concatenate two sources of data (observables) is the concat() operator. This operator receives multiple observables as arguments and concatenates all observables from the left to right. It preserves the order of the elements in the observables and only propagates data from the next observable if the current one is already terminated.

This operator has the following signature:

observable.concat(observables); 

It accepts any number of arguments, but they all must be observables:

  • observable: It is any number of observables

The easiest possible example is to use it to combine two observables:

Rx.Observable   .just(1)   .concat(Rx.Observable.just(2))   .subscribe((k)=>console.log(k)); 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required