Number.prototype[Symbol.iterator] = function* () { if (isNaN(this) || !isFinite(this)) { throw new ReferenceError('Non-iterable number') } const abs = Math.abs(this) const isNegative = this < 0 for (let i = 0; i < abs; i++) { yield isNegative ? -i : i } } [...10] // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] for (let i of 5) { // ... }