Uses a binary search to find the smallest index at which a value should be inserted to keep the array sorted (official Underscore docs). Stable Array helper — not deprecated.
Pass the required arguments shown below. Underscore array helpers usually return a new value — check whether the source array is mutated.
Splice in.splice(i, 0, 25) inserts without removing items.
Order kept. No full re-sort needed.
Note.splice mutates — that step is yours, not Underscore’s.
Compatibility
Browser & Runtime Support
_.sortedIndex ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.
✓ Stable · Underscore 1.x
_.sortedIndex()
Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.
100%With Underscore 1.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
_.sortedIndexUnderscore 1.x+
Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).
Frequently Asked Questions
_.sortedIndex(array, value) uses a binary search to find the smallest index where value can be inserted so an already-sorted array stays in order.
Yes. It assumes ascending sorted order. On an unsorted list the result can be wrong.
Pass a function or property name to compute the ranking value — useful for objects, e.g. 'age'.
No. It always returns a valid insert index from 0 to array.length — never -1.
_.indexOf finds where a value already is (or -1). _.sortedIndex finds where a value should go to keep sorted order.
No. It only returns an index. Use splice yourself if you want to insert.