Open In App

Lodash _.inRange() Method

Last Updated : 03 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.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 equal to the start, and then the start is set equal to 0. If the start is greater than the end the parameters are swapped to support negative ranges.

Syntax:

_.inRange(number, start, end);

Parameters:

  • 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: In this example, we are checking whether the given value is present between the given start and end number, also start number is inclusive.

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: In this example, we are checking whether the given value is present between the given start and end number and printing the result in the console.

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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads