Like _.sortedIndex, except it returns the highest index at which value should be inserted to maintain sort order (bisect right). Part of Lodash Array since 3.0.0 (stable in 4.x — 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 _.sortedLastIndex on an array. Start with this line.
Lodash
_.sortedLastIndex(array, value)
Call
What it does
_.sortedLastIndex(array, value)
Primary signature.
_.sortedLastIndex(array)
Call with an array argument.
Prefer import sortedLastIndex from "lodash/sortedLastIndex" when you want a smaller bundle.
Library declarations
Lodash
_.sortedLastIndex(array, value)
Parameters
Parameter
Description
array
Required. Sorted ascending collection to inspect
value
Required. Value whose highest insert index you want
Insert.splice(4, 0, 5) writes after the equal run.
Mutate now. Only splice changes the array — not Lodash.
Sorted stay. Result remains ascending with four 5s.
Compatibility
Browser & Runtime Support
_.sortedLastIndex is a Lodash 4.x Array helper (since 3.0.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. There is no single native Array API with the same name.
✓ Stable · Lodash 3.0.0+
_.sortedLastIndex()
Available in [email protected] full builds and the lodash/sortedLastIndex 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
_.sortedLastIndexLodash 3.0.0+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import sortedLastIndex from "lodash/sortedLastIndex" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.sortedLastIndex(array, value) uses a binary search to find the highest index where value should be inserted into a sorted ascending array so sort order stays valid. It does not insert the value — it only returns the index.
sortedIndex is bisect left (lowest insert index). sortedLastIndex is bisect right (highest insert index). With duplicates, they differ: insert before the equal run vs after it.
No. It only computes an insertion index. Use splice yourself if you want to insert.
Yes — ascending order. An unsorted array produces meaningless indexes because the binary search assumes sorted data.
Any integer from 0 through array.length inclusive — same span as _.sortedIndex.
Use import sortedLastIndex from "lodash/sortedLastIndex" or require("lodash/sortedLastIndex") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.sortedLastIndex.