Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Lodash _.clamp() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The _.clamp() method is used to clamp number within the inclusive range within the lower and upper bounds.

Syntax:

_.clamp(number, lower, upper)

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

  • number: This parameter holds the number to clamp.
  • lower: This parameter holds the lower bound.
  • upper: This parameter holds the upper bound.

Return Value: This method returns the clamped number.

Example 1:

Javascript




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


Output:

3
-2

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// Use of _.clamp method 
console.log(_.clamp(15, -13, 13)); 
console.log(_.clamp(-15, -13, 13)); 


Output:

13
-13
My Personal Notes arrow_drop_up
Last Updated : 09 Sep, 2020
Like Article
Save Article
Similar Reads
Related Tutorials