Lodash教程

Lodash range method

Syntax

_.range([start=0], end, [step=1])
Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. A step of-1 is used if a negative start is specified without an end or step. If end is not specified, it's set to start with start then set to 0.

Arguments

[start=0] (number) − The start of the range. end (number) − The end of the range. [step=1] (number) − The value to increment or decrement by.

Output

(Array) − Returns the range of numbers.

Example

var _ = require('lodash');
console.log(_.range(4));
console.log(_.range(0, 20, 5));
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ 0, 1, 2, 3 ]
[ 0, 5, 10, 15 ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4