Like _.lastIndexOf, except it performs a binary search on a sorted array. Returns the highest matching index, or -1 when the value is absent. Part of Lodash Array since 4.0.0 (stable — not deprecated). Warning: the array must already be sorted ascending.
Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.sortedLastIndexOf on an array. Start with this line.
Lodash
_.sortedLastIndexOf(array, value)
Call
What it does
_.sortedLastIndexOf(array, value)
Primary signature.
_.sortedLastIndexOf(array)
Call with an array argument.
Prefer import sortedLastIndexOf from "lodash/sortedLastIndexOf" when you want a smaller bundle.
Library declarations
Lodash
_.sortedLastIndexOf(array, value)
Parameters
Parameter
Description
array
Required. Sorted ascending collection to search
value
Required. Value to look up
Return Value
Return Value
Description
*
Highest matching index, or -1
Lodash Examples
Example 1 — Official: Highest Match Among Duplicates
Same as left. With a single occurrence, both helpers agree.
Fast. Still O(log n), not a reverse linear walk.
Example 5 — Count a Duplicate Run
Subtract the two match bounds (inclusive) to get the count.
Lodash
var arr = [4, 5, 5, 5, 6];
var lo = _.sortedIndexOf(arr, 5);
var hi = _.sortedLastIndexOf(arr, 5);
console.log(lo, hi); // 1 3
console.log(hi - lo + 1); // 3
Guard. If either helper returns -1, the value is missing.
Use. Measure plateaus in sorted scores, ids, or timestamps.
Compatibility
Browser & Runtime Support
_.sortedLastIndexOf 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 lastIndexOf, but not this binary-search variant by name.
✓ Stable · Lodash 4.0.0+
_.sortedLastIndexOf()
Available in [email protected] full builds and the lodash/sortedLastIndexOf 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
_.sortedLastIndexOfLodash 4.0.0+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import sortedLastIndexOf from "lodash/sortedLastIndexOf" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.sortedLastIndexOf(array, value) is like _.lastIndexOf, but uses a binary search on a sorted ascending array. It returns the highest index of a matching value, or -1 if the value is not present.
No. It is a read-only lookup. The array stays unchanged.
sortedIndexOf returns the lowest matching index. sortedLastIndexOf returns the highest. Pair them to measure a run of duplicates.
sortedLastIndex returns an insert boundary (always ≥ 0). sortedLastIndexOf returns a matching index or -1 when the value is missing.
Yes — ascending order. An unsorted array produces meaningless indexes because the binary search assumes sorted data.
Use import sortedLastIndexOf from "lodash/sortedLastIndexOf" or require("lodash/sortedLastIndexOf") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.sortedLastIndexOf.