Underscore.js _.max() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Collection

Definition

Returns the maximum value in list. If an iteratee is provided, it ranks each value by that criterion and returns the winning original element (official Underscore docs).

Pass the required arguments shown below. Underscore collection helpers usually return a new value — check whether the source is mutated.

Syntax

Call _.max. Start with this line.

Underscore
_.max(list, [iteratee], [context])
CallWhat it does
_.max(list, [iteratee], [context])Primary signature.
_.max(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.max(list, [iteratee], [context])

Parameters

ParameterDescription
listRequired. Collection to scan
iterateeOptional. Function or property name that returns the ranking number
contextOptional. this for a function iteratee

Return Value

Return ValueDescription
*Winning element (or -Infinity if empty)

Underscore.js Examples

Example 1 — Official: Max by Iteratee

Rank objects with a function; return the winning original object.

Underscore
var stooges = [
  { name: "moe", age: 40 },
  { name: "larry", age: 50 },
  { name: "curly", age: 60 }
];

_.max(stooges, function (stooge) {
  return stooge.age;
});
// → { name: "curly", age: 60 }
Try It Yourself

How It Works

  1. Iteratee. Each stooge is ranked by age.
  2. Compare. 40 → 50 → 60; curly has the highest score.
  3. Return. The curly object itself — not just 60.
  4. Safe. Source array is unchanged.

Example 2 — Numbers Without Iteratee

With plain numbers, compare the values directly.

Underscore
_.max([1, 5, 3, 9, 2]);
// → 9
Try It Yourself

How It Works

  1. No iteratee. Each number is its own score.
  2. Scan. Walk the list once; keep the largest.
  3. Result. 9 wins.
  4. Empty. _.max([]) would be -Infinity.

Example 3 — Property Shorthand

Pass a string to rank by that property — same idea as a short iteratee.

Underscore
var products = [
  { name: "Pen", price: 2 },
  { name: "Book", price: 12 },
  { name: "Bag", price: 5 }
];

_.max(products, "price");
// → { name: "Book", price: 12 }
Try It Yourself

How It Works

  1. Shorthand. "price" means use each object’s .price.
  2. Compare. 2 → 12 → 5; Book has the highest price.
  3. Return. The Book object, not just 12.
  4. Custom? Need a formula → use a function iteratee.

Example 4 — _.max vs _.min

Same list and criterion — opposite winners.

Underscore
var scores = [10, 40, 25];

_.max(scores);
// → 40

_.min(scores);
// → 10
Try It Yourself

How It Works

  1. Shared API. Both take a list and optional iteratee.
  2. max. Keeps the highest score (40).
  3. min. Keeps the lowest score (10).
  4. Pick by intent. Largest → max; smallest → min.

Browser & Runtime Support

_.max ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.max()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.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 Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.max(list, [iteratee], [context]) returns the single largest value in the list. With an iteratee, it ranks each value by the number the iteratee returns and gives back the winning original element.
-Infinity. Guard with _.isEmpty(list) when you need a different empty result.
Yes. A string iteratee uses that property as the ranking number — e.g. _.max(stooges, 'age').
Math.max takes numeric arguments and returns a number. _.max takes a collection, supports an iteratee for objects, and returns the original winning element.
Same API — _.max picks the largest criterion, _.min the smallest.
Yes. For a plain object it compares the object’s values and returns the largest one.

Next: _.min()

Find the smallest value or object by the same iteratee pattern.

_.min() 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