We're a place where coders share, stay up-to-date and grow their careers.
For most purposes, an iterator is actually preferable. These can be created via generators, as mentioned in the article. I wrote one in an older article of mine: dev.to/emnudge/generating-arrays-i...
class Range { constructor(min, max, step = 1) { this.val = min; this.end = max; this.step = step; } * [Symbol.iterator]() { while (this.val <= this.end) { yield this.val; this.val += this.step; } } }
For most purposes, an iterator is actually preferable. These can be created via generators, as mentioned in the article.
I wrote one in an older article of mine:
dev.to/emnudge/generating-arrays-i...