The range
function from the Underscore library allows you to create an array of numbers from a starting point up to, but not including, an ending point. The function takes up to three arguments: start
, stop
, and step
.
Here's an example of how to use the range
function in JavaScript:
index.tsx449 chars18 lines
In this example, we import the Underscore library and then use the _.range
function to create three different arrays of numbers: one from 1 to 10, one from 0 to 10 with a step of 2, and one from 5 to 0 with a step of -1.
Note that the stop
argument is not included in the resulting array, so the arrays in the example above do not include the number 11, 10, or 0, respectively.
gistlibby LogSnag