Like _.uniqBy, but designed and optimized for sorted arrays. It keeps the first element of each contiguous run that shares the same iteratee result. Part of Lodash Array since 4.0.0 (stable — not deprecated).
Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.sortedUniqBy on an array. Start with this line.
Lodash
_.sortedUniqBy(array, [iteratee])
Call
What it does
_.sortedUniqBy(array, [iteratee])
Primary signature.
_.sortedUniqBy(array)
Call with an array argument.
Prefer import sortedUniqBy from "lodash/sortedUniqBy" when you want a smaller bundle.
Library declarations
Lodash
_.sortedUniqBy(array, [iteratee])
Parameters
Parameter
Description
array
Required. Sorted source to inspect
iteratee
Optional. Invoked per element to produce the compare key
Return Value
Return Value
Description
*
New duplicate-free array
Lodash Examples
Example 1 — Official: Math.floor
Keep the first number in each integer floor group.
Safe. No throw — fine in pipelines with optional data.
Guard. Check length before assuming unique rows exist.
Compatibility
Browser & Runtime Support
_.sortedUniqBy is a Lodash 4.x Array helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.0.0+
_.sortedUniqBy()
Available in [email protected] full builds and the lodash/sortedUniqBy 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
_.sortedUniqByLodash 4.0.0+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import sortedUniqBy from "lodash/sortedUniqBy" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.sortedUniqBy(array, iteratee) returns a new array with duplicates removed, comparing only neighbors by the iteratee result. It is optimized for arrays already sorted by that iteratee.
No. It returns a new array. Object elements inside are still shared by reference.
Yes, for correct global uniqueness. Only adjacent equal iteratee values collapse. If equal keys are not next to each other, duplicates can remain.
uniqBy tracks every iteratee result seen so far and works on any order. sortedUniqBy assumes sorted input and only compares neighbors — usually faster on large sorted lists.
Use import sortedUniqBy from "lodash/sortedUniqBy" or require("lodash/sortedUniqBy") so bundlers can tree-shake. Full build: import _ from "lodash" then _.sortedUniqBy.
Functions (like Math.floor), property name strings, or other Lodash iteratee shorthands. The iteratee is invoked per element.