HomeLanguagesJavascriptLodash _.inRange() Method

Lodash _.inRange() Method

The _.inRange() method takes a number, and checks to see if it is between given start and end parameters. If the end is not specified, then it is set equals to the start, and then start is set equals 0. If the start is greater than the end the parameters are swapped to support negative ranges.

Syntax:

_.inRange(number, start, end)

Parameters: This method accepts three parameters as mentioned above and described below:

  • number: This parameter holds the number to check.
  • start: This parameter holds the start value of the range.
  • end: This parameter holds the end value of the range.

Return Value: This method returns true if the number is in the range, else false.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Use of _.inRange method 
console.log(_.inRange(12, 10)); 
console.log(_.inRange(10, 12)); 
console.log(_.inRange(5.6, 5)); 
console.log(_.inRange(5.6, 6));


Output:

false
true
false
true

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Use of _.inRange method 
console.log(_.inRange(2, 3, 5)); 
console.log(_.inRange(2, 2, 4)); 
console.log(_.inRange(4, 2, 4)); 
console.log(_.inRange(-2, -1, -5));


Output:

false
true
false
true
RELATED ARTICLES

Most Popular

Dominic
32548 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6922 POSTS0 COMMENTS
Nicole Veronica
12039 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12144 POSTS0 COMMENTS
Shaida Kate Naidoo
7059 POSTS0 COMMENTS
Ted Musemwa
7300 POSTS0 COMMENTS
Thapelo Manthata
7016 POSTS0 COMMENTS
Umr Jansen
7005 POSTS0 COMMENTS