Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ReactiveX/rxjs/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Waits for the source to complete, then emits the last N values from the source.
takeLast results in an observable that will hold up to count values in memory until the source completes. It then pushes all values in memory to the consumer in the order they were received.

Type Signature

function takeLast<T>(count: number): MonoTypeOperatorFunction<T>

Parameters

count
number
required
The maximum number of values to emit from the end of the sequence.If count <= 0, returns an empty Observable.

Returns

MonoTypeOperatorFunction<T> - A function that returns an Observable that emits at most the last count values emitted by the source Observable.

Usage Examples

Basic Example

import { range, takeLast } from 'rxjs';

const many = range(1, 100);
const lastThree = many.pipe(takeLast(3));

lastThree.subscribe(x => console.log(x));
// Output: 98, 99, 100
  • take - Takes first N values
  • takeUntil - Takes until another Observable emits
  • takeWhile - Takes while condition is true
  • last - Emits only the last value
  • skip - Skips first N values