Observable: drop() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The drop() method of the Observable interface returns a new observable that skips the given number of values at the start of the source observable.
Syntax
drop(amount)
Parameters
amount-
The number of values to drop from the start of the source observable. It should be an unsigned integer.
Return value
A new Observable. When subscribed to, it skips the first amount values emitted by the source observable, then emits the remaining values. If the source completes before emitting amount values, the returned observable completes without emitting any values.
Description
Like other observable-returning operators, this method is lazy: calling it creates a new observable without subscribing to the source. Processing starts when the returned observable is subscribed to.
If amount is 0, all source values are forwarded. Errors from the source are forwarded even while values are being skipped.
Examples
>Using drop()
This example ignores the first three button clicks, then displays a count of subsequent clicks.
const btn = document.querySelector("button");
const para = document.querySelector("p");
let countValue = 0;
function increment() {
countValue++;
para.textContent = `Click count: ${countValue}`;
}
btn.when("click").drop(3).subscribe(increment);
Specifications
| Specification |
|---|
| Observable> # dom-observable-drop> |