Skip to main content

Function: range()

range(start: number, end: number, step?: number): IterableIterator<number>

Creates an iterable with the numbers from start to stop (exclusive) with an optional step.

Parameters

ParameterTypeDescription
startnumberThe value of the first number in the range.
endnumberThe end value of the range.
step?numberThe amount to increment the range by.

Returns

IterableIterator<number>

Examples

import { range } from '@sapphire/iterator-utilities';

const iterable = range(0, 5);
console.log([...iterable]);
// Output: [0, 1, 2, 3, 4]
const iterable = range(5, 0);
console.log([...iterable]);
// Output: [5, 4, 3, 2, 1]
const iterable = range(0, 5, 2);
console.log([...iterable]);
// Output: [0, 2, 4]

Defined in

projects/utilities/packages/iterator-utilities/src/lib/range.ts:33