Creating an iterable class in JavaScript

class Class {
    *[Symbol.iterator]() {
        yield 1
        yield 2
    }
}

Iterables can be used in for..of statements, and with spread operator:

for (let x of iterable) console.log(x)
console.log([...iterable])

Iterables usage in JavaScript