💾*integers()

infinite sequence: 0, 1, 2, 3, ...

JSiterationcustom generators ⟩ *integers()

infinite sequence: 0, 1, 2, 3, ...

💾 replit:integers()

🌀 extension: Iterator - extend built-in iterable iterators.

// ⭐️ infinite sequence: 0, 1, 2 ... 
function* integers() {
    let i = 0;
    while (true) { yield i++ }
}

💈範例:

// ⭐️ iterable destructuring
const [a, b, c] = integers();
console.log(a, b, c);            // 0, 1, 2

Last updated