Ramda.js R.findIndex() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

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)
CallWhat 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

ParameterDescription
predRequired. value → Boolean. Truthy means "this is the one"
listRequired. An array (or string) to search

Return Value

Return ValueDescription
*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.

Ramda
const xs = [{ a: 1 }, { a: 2 }, { a: 3 }];

console.log(R.findIndex(R.propEq(2, "a"))(xs));
// → 1

console.log(R.findIndex(R.propEq(4, "a"))(xs));
// → -1
Try It Yourself

How It Works

  1. Build the test. R.propEq(2, "a") checks whether obj.a equals 2.
  2. Count from 0. {a: 1} is index 0 and fails. {a: 2} is index 1 and passes.
  3. Hit. Ramda returns 1 and never looks at index 2.
  4. Miss. No object has a: 4, so the result is -1.

Example 2 — Split a Sorted List at the First Match

Find where the scores of 70 and above begin, then cut the list there.

Ramda
const scores = [40, 55, 72, 90];

const i = R.findIndex(n => n >= 70, scores);
console.log(i);
// → 2

console.log(R.splitAt(i, scores));
// → [[40, 55], [72, 90]]
Try It Yourself

How It Works

  1. Test each score. 40 and 55 fail. 72 at index 2 is the first to pass.
  2. Get the index. R.findIndex returns 2 and skips 90.
  3. Split. R.splitAt(2, scores) returns the items before index 2 and the items from index 2 on.
  4. Sorted only. This works because the list is sorted. On an unsorted list, a score above 70 could also appear earlier in the list.

Example 3 — Update One Item by Id (Immutably)

Mark task 2 as done without changing the original list.

Ramda
const todos = [
  { id: 1, done: false },
  { id: 2, done: false },
  { id: 3, done: true }
];

const i = R.findIndex(R.propEq(2, "id"), todos);
const updated = R.adjust(i, R.assoc("done", true), todos);

console.log(R.pluck("done", updated));
// → [false, true, true]

console.log(R.pluck("done", todos));
// → [false, false, true]
Try It Yourself

How It Works

  1. Locate. R.findIndex(R.propEq(2, "id"), todos) returns 1.
  2. Change one slot. R.adjust(1, fn, todos) runs fn on the item at index 1 only.
  3. Copy, don’t mutate. R.assoc("done", true) returns a new object with done: true.
  4. Original intact. updated is a new array, and todos still shows task 2 as not done.

Example 4 — Guard Against -1

A safe “remove by id” helper that returns the list unchanged when the id is missing.

Ramda
const items = [{ id: 1 }, { id: 2 }, { id: 3 }];

const removeById = (id, list) => {
  const i = R.findIndex(R.propEq(id, "id"), list);
  return i === -1 ? list : R.remove(i, 1, list);
};

console.log(R.pluck("id", removeById(2, items)));
// → [1, 3]

console.log(R.pluck("id", removeById(9, items)));
// → [1, 2, 3]
Try It Yourself

How It Works

  1. Found. Id 2 is at index 1, so R.remove(1, 1, list) drops one item there.
  2. Missing. Id 9 does not exist, so i is -1.
  3. Why guard? R.remove(-1, 1, list) would count from the end and delete id 3 by mistake.
  4. Safe result. The i === -1 check returns the list untouched: [1, 2, 3].

Example 5 — findIndex vs indexOf

Use indexOf to find a known value and findIndex to find an item that meets a condition.

Ramda
const nums = [3, 8, 12, 5];

console.log(R.indexOf(12, nums));
// → 2   (exact value)

console.log(R.findIndex(n => n > 10, nums));
// → 2   (first item over 10)

const xs = [{ a: 1 }, { a: 2 }];

console.log(R.indexOf({ a: 2 }, xs));
// → 1   (Ramda compares by value)

console.log(xs.indexOf({ a: 2 }));
// → -1  (native compares by reference)
Try It Yourself

How It Works

  1. Known value. R.indexOf(12, nums) looks for 12 exactly and finds it at index 2.
  2. Condition. R.findIndex(n => n > 10, nums) asks a question about each item, and 12 is the first to pass.
  3. Objects. R.indexOf uses R.equals, so a fresh {a: 2} still matches.
  4. Native. Array.prototype.indexOf compares with ===, and a new object literal is never === to an existing one.

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 Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Chromium-based
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Android WebView Modern WebView
Full support
Internet Explorer Not a target for current Ramda releases
Legacy
Node.js Maintained LTS · npm install ramda
Supported
Bun import from "ramda"
Supported
Deno import from "npm:ramda"
Supported
R.findIndex Ramda 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.

Next: R.findLast()

Learn how to get the last item in a list that passes a test.

R.findLast() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful