Like _.indexOf, but it iterates from right to left. Returns the index of the last match, or -1 if none. Uses SameValueZero equality. Part of Lodash 4.x Array.
Pass the required arguments shown below. Lodash Array helpers usually return a new value — check whether the source array is mutated.
Syntax
Call _.lastIndexOf on an array. Start with this line.
_.lastIndexOf is a long-standing Lodash 4.x Array helper. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.x
_.lastIndexOf()
Available in [email protected] full builds and the lodash/lastIndexOf 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
_.lastIndexOfLodash 4.x
Bottom line: Safe for production once Lodash 4.x is on the page or in your bundle. Prefer import lastIndexOf from "lodash/lastIndexOf" for smaller builds. For the first match, use _.indexOf.
Frequently Asked Questions
_.lastIndexOf(array, value, fromIndex) returns the index of the last occurrence of value in array using SameValueZero equality, scanning from right to left. If not found, it returns -1.
No. It only scans backward and returns a number. The source array is unchanged.
It selects where the backward search begins (default: array.length - 1). Lodash normalizes negative values against length, similar to the native method.
indexOf returns the first match scanning forward; lastIndexOf returns the last match scanning backward from the effective start index.
Use import lastIndexOf from "lodash/lastIndexOf" or require("lodash/lastIndexOf") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.lastIndexOf.