Lodash _.orderBy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Like _.sortBy, but you can set ascending or descending per iteratee. Pass parallel iteratees and orders arrays. Returns a new sorted array. Part of Lodash 4.x Collection (since 4.0.0).

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

Syntax

Call _.orderBy on a collection. Start with this line.

Lodash
_.orderBy(collection, [iteratees], [orders])
CallWhat it does
_.orderBy(collection, [iteratees], [orders])Primary signature.
_.orderBy(collection)Call with a collection argument.

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

Library declarations
Lodash
_.orderBy(collection, [iteratees], [orders])

Parameters

ParameterDescription
collectionRequired. Array or object to sort
iterateesOptional. Sort keys / functions; default identity
ordersOptional. "asc" / "desc" per iteratee

Return Value

Return ValueDescription
*New sorted array

Lodash Examples

Example 1 — Official: User Asc, Age Desc

Primary name ascending; ages descending within each name.

Lodash
var users = [
  { user: "fred",   age: 48 },
  { user: "barney", age: 34 },
  { user: "fred",   age: 40 },
  { user: "barney", age: 36 }
];

_.orderBy(users, ["user", "age"], ["asc", "desc"]);
// → [
//     { user: "barney", age: 36 },
//     { user: "barney", age: 34 },
//     { user: "fred",   age: 48 },
//     { user: "fred",   age: 40 }
//   ]
Try It Yourself

How It Works

  1. Iteratees. ["user", "age"] — name first, age second.
  2. Orders. ["asc", "desc"] — name A→Z, age high→low.
  3. Ties. Age only compares within the same user.
  4. Safe. Original users array is not reordered.

Example 2 — Sort Age Descending

One column, newest/highest first.

Lodash
var users = [
  { user: "fred",   age: 48 },
  { user: "barney", age: 34 },
  { user: "fred",   age: 40 }
];

_.orderBy(users, "age", "desc");
// → fred 48, fred 40, barney 34
Try It Yourself

How It Works

  1. Single key. You can pass a string instead of an array.
  2. Direction. "desc" puts larger ages first.
  3. vs sortBy. _.sortBy(users, "age") would be ascending only.
  4. Result. New array; source untouched.

Example 3 — Default Ascending

Omit orders and every iteratee sorts ascending.

Lodash
var users = [
  { user: "fred",   age: 48 },
  { user: "barney", age: 34 },
  { user: "pebbles", age: 1 }
];

_.orderBy(users, "user");
// → barney, fred, pebbles
Try It Yourself

How It Works

  1. Default. No orders → ascending.
  2. Compare. String names sort A→Z.
  3. Same as. Close to _.sortBy(users, "user") for this case.
  4. When to prefer orderBy. Keep it when you may add "desc" later.

Example 4 — Primitive Numbers Descending

Sort a plain number array high to low.

Lodash
_.orderBy([3, 1, 2], [], ["desc"]);
// → [3, 2, 1]

_.orderBy([3, 1, 2], [_.identity], ["desc"]);
// → [3, 2, 1]
Try It Yourself

How It Works

  1. Identity. Elements are compared as themselves.
  2. Orders. "desc" flips to largest first.
  3. Arrays. Empty iteratees with an order still works via identity.
  4. Native. Similar goal to [...arr].sort((a, b) => b - a).

Example 5 — Function Iteratee

Sort by a computed value (string length), descending.

Lodash
_.orderBy(
  ["apple", "pie", "banana"],
  [function (word) { return word.length; }],
  ["desc"]
);
// → ["banana", "apple", "pie"]
Try It Yourself

How It Works

  1. Compute. Lengths are 6, 5, and 3.
  2. Desc. Longer words come first.
  3. Stable idea. Equal lengths keep relative order.
  4. Tip. Prefer property strings when the key already exists on the object.

Browser & Runtime Support

_.orderBy is a Lodash 4.x Collection helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Array.prototype.sort mutates and needs a custom comparator for multi-column mixed directions.

✓ Stable · Lodash 4.0+

_.orderBy()

Available in [email protected] full builds and the lodash/orderBy modular import. Works in evergreen browsers and current Node LTS 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
_.orderBy Lodash 4.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import orderBy from "lodash/orderBy" for smaller builds. Use when you need per-column asc/desc without hand-written comparators.

Frequently Asked Questions

_.orderBy(collection, iteratees, orders) returns a new array sorted by one or more iteratees. Each iteratee can be ascending or descending via the orders array.
No. It returns a new sorted array and leaves the source unchanged.
sortBy is always ascending. orderBy lets you set "asc" or "desc" per iteratee.
Every iteratee sorts ascending — same idea as sortBy for directions.
The first iteratee is primary. Later iteratees only break ties.
Use "asc" or "desc" (Lodash also accepts longer forms like "ascending" / "descending").

Next: _.partition()

Split a collection into two groups by a predicate.

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

9 people found this page helpful