endWith

signature: endWith(an: Values): Observable

Emit given value(s) on completion.


💡 If you want to start with a value instead, check out startWith!

💡 If you want to perform an action on completion, but do not want to emit a value, check out finalize!


Ultimate RxJS

Examples

Example 1: Basic endWith example

( StackBlitz )

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

const source$ = of('Hello', 'Friend', 'Goodbye');

source$
  // emit on completion
  .pipe(endWith('Friend'))
  // 'Hello', 'Friend', 'Goodbye', 'Friend'
  .subscribe(console.log(val));

Example 2: endWith multiple values

( StackBlitz )

Example 3: Comparison to finalize

( StackBlitz )

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/endWith.ts

Last updated