interators javascript code example
Example 1: what is an iterator in javascript
The iterator is an object that returns values via its method next()
Example 2: JavaScript — Generators
function* makeRangeIterator(start = 0, end = 100, step = 1) {
let iterationCount = 0;
for (let i = start; i < end; i += step) {
iterationCount++;
yield i;
}
return iterationCount;
}