Saturday, July 25, 2026
HomeLanguagesJavascriptLodash _.clamp() Method

Lodash _.clamp() Method

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

Syntax:

_.clamp(number, lower, upper);

Parameters:

  • 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: In this example, we are printing the clamped number by the use of the _.clamp() method.

Javascript




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


Output:

3
-2

Example 2: In this example, we are printing the clamped number by the use of the _.clamp() method.

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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS