A helper that searches a list from the right and returns the position of the last item that passes a test. If no item passes, it returns -1. The index is a normal zero-based position counted from the left, and the list is never changed. It has been part of Ramda List since v0.1.1 (stable, not deprecated, experimental, or non-standard).
Why the index? You need a position to insert after, cut at, or update the last match, for example with R.insert, R.take, or R.adjust. If you only want the item, use R.findLast.
Syntax
Call R.findLastIndex. Start with this line.
Ramda
R.findLastIndex(pred, list)
Call
What it does
R.findLastIndex(pred, list)
Primary signature.
R.findLastIndex(...)
Call the list helper.
Prefer import { findLastIndex } from "ramda" when you want a named import.
Library declarations
Ramda
R.findLastIndex(pred, list)
Parameters
Parameter
Description
pred
Required. value → Boolean. Truthy means "this is the one"
list
Required. An array (or string) to search
Return Value
Return Value
Description
*
A number: the last matching index, or -1
Ramda Examples
Example 1 — Official Samples vs R.findIndex
Two objects match. The last one is at index 1, and the first is at index 0.
R.findLastIndex has been a Ramda List helper since v0.1.1. It uses its own backward loop, so it does not need the ES2023 Array.prototype.findLastIndex (Chrome 97+, Firefox 104+, Safari 15.4+, Node.js 18+). It runs anywhere Ramda runs.
✓ Stable · Ramda 0.1.1+
R.findLastIndex()
Support depends on the Ramda version you load, not on a browser feature. Your own test must also be valid in that runtime. For example, arrow functions need an ES2015 engine.
100%Modern browsers & runtimes
Google ChromeModern versions · Desktop & Mobile
Full support
Mozilla FirefoxModern versions · Desktop & Mobile
Full support
Apple SafariModern versions · macOS & iOS
Full support
Microsoft EdgeChromium-based
Full support
OperaModern versions
Full support
Samsung InternetModern versions · Android
Full support
Android WebViewModern WebView
Full support
Internet ExplorerNot a target for current Ramda releases
Legacy
Node.jsMaintained LTS · npm install ramda
Supported
Bunimport from "ramda"
Supported
Denoimport from "npm:ramda"
Supported
R.findLastIndexRamda 0.1.1+
Bottom line: Safe for production in any modern browser or JavaScript runtime once Ramda is loaded, including engines that predate the native findLastIndex. The labs on this page use [email protected] from a CDN.
Frequently Asked Questions
R.findLastIndex(pred, list) searches from the right and returns the index of the last item for which pred returns a truthy value, or -1 if no item passes. Docs sample: with xs = [{a: 1, b: 0}, {a: 1, b: 1}], R.findLastIndex(R.propEq(1, 'a'))(xs) //=> 1.
No. The search runs right to left, but the index is a normal zero-based position counted from the left. In [5, 8, 8], the last 8 is at index 2.
R.lastIndexOf looks for a known value and compares with R.equals. R.findLastIndex looks for the last item that passes a test, such as n => n < 3.
Both return the last matching index or -1. The native method arrived in ES2023 (Chrome 97, Firefox 104, Safari 15.4, Node.js 18). R.findLastIndex works in any engine Ramda supports and is curried for R.pipe.
R.update, R.remove, R.adjust, and R.nth treat -1 as the last item. An unchecked miss silently edits or reads the last element. Compare with i !== -1 first.
No. R.findLastIndex has been part of Ramda since v0.1.1 and is stable. It is not deprecated, experimental, or non-standard.