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

Creating an observable using range ()

Another common source of data for observables are ranges. With the range() method, we can easily create an observable for a sequence of values in a range. The range() method has the following signature:

Rx.Observable.range(first, count, [scheduler]); 

The last parameter in the following list is the only optional parameter in this method:

  • first: This is the initial integer value in the sequence
  • count: This is the number of sequential integers to be iterated from the beginning of the sequence
  • scheduler: This is used to generate the values

We can create an observable using a range with the following code:

Rx.Observable     .range(0, 4)     .subscribe((i)=>console.log(i)); 

This prints the following output: ...

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