Function range

  • A generator to yield numbers in a given range

    Parameters

    • range: number | RangeOptions

      A number representing the range to yield (exclusive) or an object with start, end and step

    Returns Generator<number, void, unknown>

    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

    Example

    Range with a step

    for (const number of range({ start: 3, end: 10, step: 2 })) {
    console.log(number);
    }
    // Prints 3, 5, 7, 9

Generated using TypeDoc