Creating an iterable object in JavaScript

obj = {
    [Symbol.iterator]: function* () {
        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