| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Iterator/drop | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
Since 2025 3, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Iterator drop() .
drop(limit)
limit.
. next() , limit , (limit+1 ) . . limit , next() .
RangeError limit NaN .
, 3 .
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
.
const seq = fibonacci();
seq.next();
seq.next();
drop() . , for...of .
for (const n of fibonacci().drop(2)) {
console.log(n);
if (n > 30) {
break;
}
}
// Logs:
// 2
// 3
// 5
// 8
// 13
// 21
// 34
drop() Iterator.prototype.take() .
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
limit NaN RangeError .
fibonacci().drop(-1); // RangeError: -1 must be positive
fibonacci().drop(undefined); // RangeError: undefined must be positive
limit (: Infinity), next() . , .
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 |
This page was last modified on 2024 7 27 by MDN contributors.
IteratorObject/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |