Learn RxJS
Search…
of

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

Emit variable amount of values in a sequence and then emits a complete notification.

Examples

Example 1: Emitting a sequence of numbers
1
// RxJS v6+
2
import { of } from 'rxjs';
3
//emits any number of provided values in sequence
4
const source = of(1, 2, 3, 4, 5);
5
//output: 1,2,3,4,5
6
const subscribe = source.subscribe(val => console.log(val));
Copied!
Example 2: Emitting an object, array, and function
1
// RxJS v6+
2
import { of } from 'rxjs';
3
//emits values of any type
4
const source = of({ name: 'Brian' }, [1, 2, 3], function hello() {
5
return 'Hello';
6
});
7
//output: {name: 'Brian'}, [1,2,3], function hello() { return 'Hello' }
8
const subscribe = source.subscribe(val => console.log(val));
Copied!

Additional Resources

Last modified 6mo ago