Creating Observables From Javascript Data Types
Learn to create and use Observables from JavaScript data types like arrays, events, and callback functions.
Creating Observables from arrays
We can make any array-like object that can iterate into an Observable by using the versatile from
operator. The from
operator takes an array as a parameter and returns an Observable that emits each of its elements.
Press + to interact
Rx.Observable.from(['Adrià', 'Jen', 'Sergi']).subscribe(function(x){console.log('Next: ' + x);},function(err){console.log('Error:', err);},function(){console.log('Completed');});
The from
operator is, along with the fromEvent
operator, one of the most convenient and frequently used operators in RxJS code.
Creating Observables from JavaScript events
When ...
Access this course and 1400+ top-rated courses and projects.