githubEdit

startWith

signature: startWith(an: Values): Observable

Emit given value first.


๐Ÿ’ก A BehaviorSubjectarrow-up-right can also start with an initial value!


Ultimate RxJSarrow-up-right

Examples

( example testsarrow-up-right )

Example 1: startWith on number sequence

( StackBlitzarrow-up-right | jsBinarrow-up-right | jsFiddlearrow-up-right )

// RxJS v6+
import { startWith } from 'rxjs/operators';
import { of } from 'rxjs';

//emit (1,2,3)
const source = of(1, 2, 3);
//start with 0
const example = source.pipe(startWith(0));
//output: 0,1,2,3
const subscribe = example.subscribe(val => console.log(val));

Example 2: startWith for initial scan value

( StackBlitzarrow-up-right | | jsBinarrow-up-right | jsFiddlearrow-up-right )

Example 3: startWith multiple values

( StackBlitzarrow-up-right | jsBinarrow-up-right | jsFiddlearrow-up-right )

Additional Resources


๐Ÿ“ Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/startWith.tsarrow-up-right

Last updated