of

signature: of(...values, scheduler: Scheduler): Observable

Emit variable amount of values in a sequence.

Examples

Example 1: Emitting a sequence of numbers

( jsBin |
jsFiddle )

  1. //emits any number of provided values in sequence
  2. const source = Rx.Observable.of(1, 2, 3, 4, 5);
  3. //output: 1,2,3,4,5
  4. const subscribe = source.subscribe(val => console.log(val));
Example 2: Emitting an object, array, and function

( jsBin |
jsFiddle )

  1. import { of } from 'rxjs/observable/of';
  2. //emits values of any type
  3. const source = of({ name: 'Brian' }, [1, 2, 3], function hello() {
  4. return 'Hello';
  5. });
  6. //output: {name: 'Brian}, [1,2,3], function hello() { return 'Hello' }
  7. const subscribe = source.subscribe(val => console.log(val));

Additional Resources


:file_folder: Source Code:
https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/of.ts