| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Iterator/map | [Back] [Original] |
Get to know MDN better
map(callbackFn)
next() callbackFn next() { value: undefined, done: true }
map()
2
function* fibonacci() {
let current = 1;
let next = 1;
while (true) {
yield current;
[current, next] = [next, current + next];
}
}
const seq = fibonacci().map((x) => x ** 2);
console.log(seq.next().value); // 1
console.log(seq.next().value); // 1
console.log(seq.next().value); // 4
map() for...of
for (const n of fibonacci().map((x) => x ** 2)) {
console.log(n);
if (n > 30) {
break;
}
}
// Logs:
// 1
// 1
// 4
// 9
// 25
// 64
This is equivalent to:
for (const n of fibonacci()) {
const n2 = n ** 2;
console.log(n2);
if (n2 > 30) {
break;
}
}
| ECMAScript 2027 LanguageSpecification # sec-iterator.prototype.map |
| Web Proxy Viewer | New URL | Original Page |