last
#last
signature: last(predicate: function): Observable
Emit the last value emitted from source on completion, based on provided expression.
💡 The counterpart to last is first!
Examples
Example 1: Last value in sequence
( StackBlitz | jsBin | jsFiddle )
// RxJS v6+
import { from } from 'rxjs';
import { last } from 'rxjs/operators';
const source = from([1, 2, 3, 4, 5]);
//no arguments, emit last value
const example = source.pipe(last());
//output: "Last value: 5"
const subscribe = example.subscribe(val => console.log(`Last value: ${val}`));Example 2: Last value to pass predicate
( StackBlitz | jsBin | jsFiddle )
Example 3: Last with default value
( StackBlitz | jsBin | jsFiddle )
Additional Resources
last 📰 - Official docs
Filtering operator: takeLast, last 🎥 💵 - André Staltz
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/last.ts
Last updated