Lodash Math Methods

About This Index
This page is the Lodash Math index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn lang checks on /lodash/lang. Use this page when you need math helpers such as _.add(), _.round(), or _.sum().
Start with _.add(), then _.round(), _.max(), and _.sum()—then open the *By variants for object arrays.
How to Call a Math Method
Pass numbers (or an array for aggregators) to the Lodash helper:
import _ from "lodash";
_.add(6, 4); // 10
_.subtract(6, 4); // 2
_.multiply(6, 4); // 24
_.divide(6, 4); // 1.5
_.round(4.006, 2); // 4.01
_.ceil(6.004, 2); // 6.01
_.floor(0.046, 2); // 0.04
_.max([4, 2, 8, 6]); // 8
_.sum([4, 2, 8, 6]); // 20
_.mean([4, 2, 8, 6]); // 5
_.maxBy([{ n: 1 }, { n: 2 }], "n"); // { n: 2 } Lodash Math Methods Table
All math method guides in this Lodash tutorial series (15 tutorials).
Arithmetic
4 methodsAdd, subtract, multiply, and divide two numbers.
| Method | Description | Tutorial |
|---|---|---|
_.add() | Add two numbers. Undefined operands are treated as 0. | Try it |
_.subtract() | Subtract the second number from the first. Undefined operands are treated as 0. | Try it |
_.multiply() | Multiply two numbers. Undefined operands are treated as 1. | Try it |
_.divide() | Divide two numbers. Undefined operands are treated as 1. | Try it |
Rounding
3 methodsCeil, floor, and round with optional precision.
Min & Max
4 methodsFind extremes in an array, optionally by iteratee.
| Method | Description | Tutorial |
|---|---|---|
_.max() | Largest element in an array. Returns undefined when the array is empty. | Try it |
_.maxBy() | Like max, but each element is ranked by an iteratee. | Try it |
_.min() | Smallest element in an array. Returns undefined when the array is empty. | Try it |
_.minBy() | Like min, but each element is ranked by an iteratee. | Try it |
Aggregate
4 methodsSum and mean over arrays, with iteratee variants.
| Method | Description | Tutorial |
|---|---|---|
_.sum() | Sum of an array of numbers. Returns 0 when the array is empty. | Try it |
_.sumBy() | Like sum, but each element is projected by an iteratee before adding. | Try it |
_.mean() | Arithmetic mean of an array of numbers. Returns NaN when empty. | Try it |
_.meanBy() | Like mean, but each element is projected by an iteratee first. | Try it |
Frequently Asked Questions
Start with _.add()
Open the addition 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.
10 people found this page helpful
