signature: takeLast(count: number): Observable

Emit the last n emitted values before completion

:bulb: If you want only the last emission from multiple observables, on completion of multiple observables, try forkJoin!


Example 1: take the last 2 emitted values before completion

( StackBlitz )

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

const source = of('Ignore', 'Ignore', 'Hello', 'World!');
// take the last 2 emitted values
const example = source.pipe(takeLast(2));
// Hello, World!
const subscribe = example.subscribe(val => console.log(val));

Additional Resources

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

results matching ""

    No results matching ""