Like _.uniq, except it is designed and optimized for sorted arrays. It keeps one value from each consecutive equal run and returns a new array. Part of Lodash Array since 4.0.0 (stable — not deprecated). Warning: the array must already be sorted ascending when you need full uniqueness.
Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.sortedUniq on an array. Start with this line.
Lodash
_.sortedUniq(array)
Call
What it does
_.sortedUniq(array)
Primary signature.
_.sortedUniq(array)
Call with an array argument.
Prefer import sortedUniq from "lodash/sortedUniq" when you want a smaller bundle.
Library declarations
Lodash
_.sortedUniq(array)
Parameters
Parameter
Description
array
Required. Sorted ascending collection to dedupe
Return Value
Return Value
Description
*
New array with consecutive duplicates removed
Lodash Examples
Example 1 — Official: Collapse Consecutive Duplicates
Unique. Every neighbor differs → every value is kept.
New array. Still returns a fresh array (not the same reference).
Safe. Safe defaults for pipelines that may receive empty lists.
Compatibility
Browser & Runtime Support
_.sortedUniq 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. Native engines have Set / spread patterns, but not this sorted-optimized helper by name.
✓ Stable · Lodash 4.0.0+
_.sortedUniq()
Available in [email protected] full builds and the lodash/sortedUniq 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
_.sortedUniqLodash 4.0.0+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import sortedUniq from "lodash/sortedUniq" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.sortedUniq(array) is like _.uniq, but optimized for sorted arrays. It keeps one value from each consecutive equal run and returns a new array.
No. Lodash builds and returns a new array. The source array stays unchanged.
No. You must pass an ascending sorted array when you need global uniqueness. On unsorted data it only removes adjacent duplicates.
uniq tracks every prior value across the whole array and works on unsorted input. sortedUniq only compares neighbors, so it is faster when the array is already sorted.
Adjacent pairs use SameValueZero semantics — the same rule Lodash uses for other uniqueness helpers (NaN equals NaN, 0 equals -0).
Use import sortedUniq from "lodash/sortedUniq" or require("lodash/sortedUniq") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.sortedUniq.