Back to Rxjs

This is RxJS v 4. Find the latest version here

doc/api/core/operators/takelast.md

4.1.02.3 KB
Original Source

This is RxJS v 4. Find the latest version here

Rx.Observable.prototype.takeLast(count)

Returns a specified number of contiguous elements from the end of an observable sequence, using an optional scheduler to drain the queue.

This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.

Arguments

  1. count (Number): Number of elements to bypass at the end of the source sequence.

Returns

(Observable): An observable sequence containing the source sequence elements except for the bypassed ones at the end.

Example

js
var source = Rx.Observable.range(0, 5)
    .takeLast(3);

var subscription = source.subscribe(
    function (x) {
        console.log('Next: ' + x);
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    });

// => Next: 2
// => Next: 3
// => Next: 4
// => Completed

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests: