A helper that returns the position of the first item that passes a test. If no item passes, it returns -1. It stops checking as soon as it finds a match, and it never changes the list. It has been part of Ramda List since v0.1.1 (stable, not deprecated, experimental, or non-standard).
Why the index and not the item? You need a position to update, remove, or split at a spot, for example with R.adjust or R.remove. If you only want the item itself, use R.find.
Syntax
Call R.findIndex. Start with this line.
Ramda
R.findIndex(pred, list)
Call
What it does
R.findIndex(pred, list)
Primary signature.
R.findIndex(...)
Call the list helper.
Prefer import { findIndex } from "ramda" when you want a named import.
Library declarations
Ramda
R.findIndex(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 first matching index, or -1
Ramda Examples
Example 1 — Official Hit and Miss
Find the position of a: 2, then of a: 4, which is not in the list.
Known value.R.indexOf(12, nums) looks for 12 exactly and finds it at index 2.
Condition.R.findIndex(n => n > 10, nums) asks a question about each item, and 12 is the first to pass.
Objects.R.indexOf uses R.equals, so a fresh {a: 2} still matches.
Native.Array.prototype.indexOf compares with ===, and a new object literal is never === to an existing one.
Compatibility
Browser & Runtime Support
R.findIndex has been a Ramda List helper since v0.1.1. It uses its own loop rather than the ES2015 Array.prototype.findIndex, so it runs anywhere Ramda runs. In the browser, load it from a CDN or a bundler. In Node.js, Bun, or Deno, run npm install ramda.
✓ Stable · Ramda 0.1.1+
R.findIndex()
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.findIndexRamda 0.1.1+
Bottom line: Safe for production in any modern browser or JavaScript runtime once Ramda is loaded. The labs on this page use [email protected] from a CDN.
Frequently Asked Questions
R.findIndex(pred, list) returns the index of the first item for which pred returns a truthy value, or -1 if no item passes. It stops checking at the first match. Docs sample: R.findIndex(R.propEq(2, 'a'))([{a: 1}, {a: 2}, {a: 3}]) //=> 1.
Both return the first matching index or -1. R.findIndex is curried and data-last, so R.findIndex(isDone) is a reusable function for R.pipe. Its predicate receives only the value, with no index or array argument.
R.indexOf looks for a known value and compares with R.equals, so R.indexOf({a: 2}, xs) works on objects. R.findIndex looks for the first item that passes a test, such as n => n > 10.
Ramda helpers like R.update, R.remove, R.adjust, and R.nth treat negative indexes as counting from the end. Passing -1 by mistake silently changes or reads the last item. Always check i !== -1 first.
The first item has index 0, which is falsy, while -1 is truthy. Compare explicitly with index !== -1 or index >= 0.
No. R.findIndex has been part of Ramda since v0.1.1 and is stable. It is not deprecated, experimental, or non-standard.