Computes the sum of the values in array. Part of Lodash Math (stable — not deprecated). Empty, null, and undefined arrays return 0 (unlike _.mean([]), which is NaN).
Pass the numbers or collection shown below. Check the return value before you chain another math helper.
Syntax
Call _.sum. Start with this line.
Lodash
_.sum(array)
Call
What it does
_.sum(array)
Primary signature.
Prefer import sum from "lodash/sum" when you want a smaller bundle.
_.sum is a Lodash Math helper available in 4.x (and earlier builds). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native equivalents use array.reduce((a, b) => a + b, 0); Lodash additionally returns 0 for empty/nullish input.
✓ Stable · Lodash 4.x
_.sum()
Available in [email protected] full builds and the lodash/sum modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.sumLodash 4.x
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import sum from "lodash/sum" for smaller builds. Keep the list numeric — strings concatenate.
Frequently Asked Questions
_.sum(array) computes the sum of the values in array. Official docs: _.sum([4, 2, 8, 6]) → 20. Empty, null, and undefined arrays return 0.
_.sum short-circuits empty/nullish input to 0. _.mean divides sum by length, so empty becomes 0 / 0 → NaN.
Lodash uses native +. After the first number, hitting a string switches to string concatenation: 1 + '2' → '12', then '12' + 3 → '123'. Coerce with _.sum(arr.map(Number)) when needed.
No. _.sum([0.1, 0.2]) can still show 0.30000000000000004 — same as native +. For money, work in integer cents or use a decimal library.
Use _.sumBy when items are objects and you need to sum a property or iteratee result — for example _.sumBy(users, 'age'). _.sum expects a flat list of numbers.
Use import sum from "lodash/sum" or require("lodash/sum") so bundlers can tree-shake. Full build: import _ from "lodash" then _.sum.