Returns a generator for a sequence of numbers in the given range, starting from start (default 0) to stop (not-inclusive) in increments of step (default 1).
range(x) is a shorthand for range(0, x, 1).
Example
range(5) // [0, 1, 2, 3, 4]
range(2, 5) // [2, 3, 4]
range(0, 5, 2) // [0, 2, 4]
range(5, 0, -1) // [5, 4, 3, 2, 1]
range(-3) // []
Parameters
Rest...args: number[]
When called with a single argument, it is assigned to stop param. If two arguments are given, it will assign them to (start, stop). When three arguments, it means (start, stop, step).
Returns a generator for a sequence of numbers in the given range, starting from
start
(default 0) tostop
(not-inclusive) in increments ofstep
(default 1).range(x)
is a shorthand forrange(0, x, 1)
.Example