Skip to content
RED SAG Skills
hard20 pts · first answer countsjavascriptiterators

Making an object spreadable

Why does [...range] work here but [...{ from: 1, to: 3 }] throws?

const range = {
  from: 1, to: 3,
  *[Symbol.iterator]() {
    for (let i = this.from; i <= this.to; i++) yield i
  },
}
console.log([...range]) // [1, 2, 3]
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions