Lodash _.max() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Math

Definition

Computes the maximum value of array. If array is empty or falsey, undefined is returned. Part of Lodash 4.x Math (since 0.1.0).

Pass the numbers or collection shown below. Check the return value before you chain another math helper.

Syntax

Call _.max. Start with this line.

Lodash
_.max(array)
CallWhat it does
_.max(array)Primary signature.

Prefer import max from "lodash/max" when you want a smaller bundle.

Library declarations
Lodash
_.max(array)

Parameters

ParameterDescription
arrayRequired. Collection to scan

Return Value

Return ValueDescription
*Maximum value, or undefined if empty/falsey

Lodash Examples

Example 1 — Official Maximum

Find the largest number in a list.

Lodash
_.max([4, 2, 8, 6]);
// → 8
Try It Yourself

How It Works

  1. Scan. Lodash walks the array once.
  2. Compare. Keeps the greater value at each step.
  3. Result. 8 wins — same as the official docs.
  4. Return. The element itself (not an index).

Example 2 — Empty / Falsey → undefined

No values means no maximum.

Lodash
[
  _.max([]),
  _.max(null),
  _.max(undefined)
];
// → [undefined, undefined, undefined]
Try It Yourself

How It Works

  1. Guard. Lodash checks array && array.length.
  2. Fail. Empty or falsey input short-circuits.
  3. Result. undefined — not -Infinity.
  4. App tip. Default with _.max(arr) ?? 0 when needed.

Example 3 — Negative Numbers

Works the same for negatives — larger means closer to +∞.

Lodash
_.max([-10, -3, -7]);
// → -3
Try It Yourself

How It Works

  1. Compare. -3 > -7 and -3 > -10.
  2. Winner. -3 is the maximum.
  3. Min twin. _.min([-10, -3, -7]) → -10.
  4. Use. Same API for positive or negative lists.

Example 4 — Skips NaN

Invalid numeric candidates are ignored while scanning.

Lodash
[
  _.max([1, NaN, 3]),
  _.max([NaN, NaN])
];
// → [3, undefined]
Try It Yourself

How It Works

  1. Skip. NaN (and typically null / undefined) is not kept as a candidate.
  2. Keep. Valid numbers still compete → 3.
  3. All bad. Only NaN values → undefined.
  4. Clean data. Prefer filtering first when invalid entries matter.

Example 5 — max vs maxBy

Objects need an iteratee — that is maxBy, not max.

Lodash
var users = [
  { name: "a", age: 20 },
  { name: "b", age: 40 },
  { name: "c", age: 30 }
];

_.maxBy(users, "age");
// → { name: "b", age: 40 }

// _.max(users) is not useful for object scores
Try It Yourself

How It Works

  1. max. Compares elements as-is — for plain numbers.
  2. maxBy. Compares by "age" (or a function).
  3. Footgun. A second arg to _.max is ignored in Lodash 4.x.
  4. Pick. Numbers → max. Objects → maxBy.

Browser & Runtime Support

_.max is a Lodash 4.x Math helper (since 0.1.0). It needs no special browser APIs beyond loading Lodash.

✓ Stable · Lodash 0.1.0+

_.max()

Available in [email protected] full builds and the lodash/max modular import. Works in evergreen browsers and Node / Bun / Deno when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.max Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import max from "lodash/max" for smaller builds.

Frequently Asked Questions

_.max(array) returns the maximum value in array. Official docs: _.max([4, 2, 8, 6]) → 8. Empty or falsey arrays return undefined.
_.max([]) returns undefined. Same for null and undefined input.
No. Lodash 4.x takes only the array. A second argument is ignored. Use _.maxBy for objects or custom criteria.
Math.max(...arr) spreads arguments and returns -Infinity on no args. _.max(arr) takes one array and returns undefined when empty.
Yes in practice — null, undefined, and NaN candidates are skipped while finding the extremum. An array of only NaN values yields undefined.
Use import max from "lodash/max" or require("lodash/max") for tree-shaking. Full build: import _ from "lodash" then _.max.

Next: _.maxBy()

Find the maximum element using a property path or iteratee.

_.maxBy() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful