range

export declare function range(range: RangeOptions | number): Generator<number, void, unknown>;
export declare function range(range: RangeOptions | number): Generator<number, void, unknown>;
A generator to yield numbers in a given range
Remarks
This method is end-exclusive, for example the last number yielded by range(5) is 4. If you prefer for the end to be included add 1 to the range or end option.
Example
Basic range
for (const number of range(5)) {
console.log(number);
}
// Prints 0, 1, 2, 3, 4
for (const number of range(5)) {
console.log(number);
}
// Prints 0, 1, 2, 3, 4
Example
Range with a step
for (const number of range({ start: 3, end: 10, step: 2 })) {
console.log(number);
}
// Prints 3, 5, 7, 9
for (const number of range({ start: 3, end: 10, step: 2 })) {
console.log(number);
}
// Prints 3, 5, 7, 9
NameTypeOptionalDescription
rangeRangeOptions | numberNoA number representing the the range to yield (exclusive) or an object with start, end and step