[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Iterator/drop [Back]  [Original]

Iterator.prototype.drop() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Iterator.prototype.drop()

Baseline 2025
Newly available

Since 2025 3, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Experimental: .
.

Iterator drop() .

In this article

js
drop(limit)

limit

.

. next() , limit , (limit+1 ) . . limit , next() .

RangeError

limit NaN .

drop()

, 3 .

js
function* fibonacci() {
  let current = 1;
  let next = 1;
  while (true) {
    yield current;
    [current, next] = [next, current + next];
  }
}

const seq = fibonacci().drop(2);
console.log(seq.next().value); // 2
console.log(seq.next().value); // 3

.

js
const seq = fibonacci();
seq.next();
seq.next();

for...of drop()

drop() . , for...of .

js
for (const n of fibonacci().drop(2)) {
  console.log(n);
  if (n > 30) {
    break;
  }
}

// Logs:
// 2
// 3
// 5
// 8
// 13
// 21
// 34

drop() take()

drop() Iterator.prototype.take() .

js
for (const n of fibonacci().drop(2).take(5)) {
  //     ,  5 
  console.log(n);
}
// :
// 2
// 3
// 5
// 8
// 13

for (const n of fibonacci().take(5).drop(2)) {
  //  5 ,  2 
  console.log(n);
}
// :
// 2
// 3
// 5

drop

limit NaN RangeError .

js
fibonacci().drop(-1); // RangeError: -1 must be positive
fibonacci().drop(undefined); // RangeError: undefined must be positive

limit (: Infinity), next() . , .

js
fibonacci().drop(Infinity).next(); // Never ends
new Set([1, 2, 3]).values().drop(Infinity).next(); // { value: undefined, done: true }
new Set([1, 2, 3]).values().drop(4).next(); // { value: undefined, done: true }

Specification
ECMAScript 2027 LanguageSpecification
# sec-iterator.prototype.drop


Web Proxy Viewer  |  New URL  |  Original Page