The takeLast() operator is analogous to the take() operator. The only difference is it takes a given count from the end of the observable. It has the following signature:
The first parameter is mandatory:
- count: This is the number of elements to be retrieved from the end of the observable
We can change the example from the previous section to use this operator:
Rx.Observable .of(1,3,5) .takeLast(2) .subscribe((i)=>console.log(i));
In this code, the takeLast() operator generates a new Observable containing the last two elements in the original Observable (3 and 5), so, if you run this code, you will see the following output:
This operation is illustrated in the following diagram: ...