Does JavaScript have a method like “range()” to generate a range within the supplied bounds?

后端 未结 30 2822
广开言路
广开言路 2020-11-22 00:51

In PHP, you can do...

range(1, 3); // Array(1, 2, 3)
range(\"A\", \"C\"); // Array(\"A\", \"B\", \"C\")

That is, there is a function that l

30条回答
  •  梦谈多话
    2020-11-22 01:43

    d3 also has a built-in range function. See https://github.com/mbostock/d3/wiki/Arrays#d3_range:

    d3.range([start, ]stop[, step])

    Generates an array containing an arithmetic progression, similar to the Python built-in range. This method is often used to iterate over a sequence of numeric or integer values, such as the indexes into an array. Unlike the Python version, the arguments are not required to be integers, though the results are more predictable if they are due to floating point precision. If step is omitted, it defaults to 1.

    Example:

    d3.range(10)
    // returns [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    

提交回复
热议问题