大网数据广告活动
Web 标准与前端开发

Observable: drop() method

· 52CE 我爱测

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.

Observable API

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.

<button>Click me</button>
<p>Click count: 0</p>
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);

basic-drop

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。