Lodash Number Methods

About This Index
This page is the Lodash Number index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn math aggregators on /lodash/math. Use this page for bounds and randomness with _.clamp(), _.inRange(), and _.random().
Start with _.clamp(), then _.inRange() for half-open intervals, and _.random() for bounded picks (not crypto).
How to Call a Number Method
Pass a number and bounds to the Lodash helper:
import _ from "lodash";
_.clamp(-10, -5, 5); // -5
_.clamp(10, -5, 5); // 5
_.clamp(3, -5, 5); // 3
_.inRange(3, 2, 4); // true (2 <= 3 < 4)
_.inRange(4, 2, 4); // false (end exclusive)
_.inRange(2, 2); // false (defaults start=0, end=2)
_.random(0, 5); // integer 0..5
_.random(1.2, 5.2); // float in range
_.random(5); // integer 0..5 Lodash Number Methods Table
All number method guides in this Lodash tutorial series (3 tutorials).
Bounds
2 methodsClamp values and test half-open numeric ranges.
| Method | Description | Tutorial |
|---|---|---|
_.clamp() | Constrain a number between a lower and upper bound. | Try it |
_.inRange() | Return true when the number lies in the half-open interval [start, end). | Try it |
Generate
1 methodCreate bounded random integers or floats.
| Method | Description | Tutorial |
|---|---|---|
_.random() | Produce a random integer or floating value between bounds. | Try it |
Frequently Asked Questions
Start with _.clamp()
Open the clamp guide—syntax, examples, and FAQs.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
8 people found this page helpful
