Uses a binary search to determine the lowest index at which value should be inserted into array to maintain its sort order. Part of Lodash Array since 0.1.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 _.sortedIndex on an array. Start with this line.
Lodash
_.sortedIndex(array, value)
Call
What it does
_.sortedIndex(array, value)
Primary signature.
_.sortedIndex(array)
Call with an array argument.
Prefer import sortedIndex from "lodash/sortedIndex" when you want a smaller bundle.
Mutate now. Only splice changes the array — not Lodash.
Sorted stay. Result remains ascending.
Compatibility
Browser & Runtime Support
_.sortedIndex is a Lodash 4.x Array helper (since 0.1.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; binary-search insert helpers are library-level.
✓ Stable · Lodash 0.1.0+
_.sortedIndex()
Available in [email protected] full builds and the lodash/sortedIndex 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
_.sortedIndexLodash 0.1.0+
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import sortedIndex from "lodash/sortedIndex" for smaller builds. Not a native browser API — load Lodash first.
Frequently Asked Questions
_.sortedIndex(array, value) uses a binary search to find the lowest index where value should be inserted into a sorted ascending array so the sort order stays valid. It does not insert the value — it only returns the index.
No. It only computes an insertion index. Use splice (or similar) yourself if you want to insert.
Yes — ascending order for the default comparator. An unsorted array produces meaningless indexes because the binary search assumes sorted data.
Lodash returns the leftmost insert point (bisect left) — the smallest index among equal values. For the rightmost insert point, use _.sortedLastIndex.
indexOf scans for an exact match in any array (linear). sortedIndex answers where to insert in a sorted array (logarithmic) and may return an index even when the value is not present.
Use import sortedIndex from "lodash/sortedIndex" or require("lodash/sortedIndex") so bundlers can tree-shake unused Lodash code. Full build: import _ from "lodash" then _.sortedIndex.