Lodash - inRange method



Syntax

_.inRange(number, [start=0], end)

Checks if n is between start and up to, but not including, end. If end is not specified, it's set to start with start then set to 0. If start is greater than end the params are swapped to support negative ranges.

Arguments

  • number (number) − The number to check.

  • [start=0] (number) − The start of the range.

  • end (number) − The end of the range.

Output

  • (boolean) − Returns true if number is in the range, else false.

Example

var _ = require('lodash');
var result = _.inRange(-12, -22, 2);

console.log(result);

result = _.inRange(12, -22, 2);
console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

true
false
lodash_number.htm
Advertisements