| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Iterator/filter | [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 filter() true .
filter(callbackFn)
. next() , true . , (next() { value: undefined, done: true } ).
. filter() .
.
function* fibonacci() {
let current = 1;
let next = 1;
while (true) {
yield current;
[current, next] = [next, current + next];
}
}
const seq = fibonacci().filter((x) => x % 2 === 0);
console.log(seq.next().value); // 2
console.log(seq.next().value); // 8
console.log(seq.next().value); // 34
filter() . , for...of .
for (const n of fibonacci().filter((x) => x % 2 === 0)) {
console.log(n);
if (n > 30) {
break;
}
}
// Logs:
// 2
// 8
// 34
.
for (const n of fibonacci()) {
if (n % 2 !== 0) {
continue;
}
console.log(n);
if (n > 30) {
break;
}
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-iterator.prototype.filter |
core-js Iterator.prototype.filter IteratorIterator.prototype.forEach()Iterator.prototype.every()Iterator.prototype.map()Iterator.prototype.some()Iterator.prototype.reduce()Array.prototype.filter()This page was last modified on 2024 10 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 |