Ramda.js R.findLast() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A helper that searches a list from the right and returns the last item that passes a test. If no item passes, it returns undefined. It stops at the first match it meets (which is the last one in the list) and never changes the list. It has been part of Ramda List since v0.1.1 (stable, not deprecated, experimental, or non-standard).

Why not the native method? Array.prototype.findLast only arrived in ES2023, and you have to call it on the data. R.findLast(isError) works in older engines too, and it is curried, so it slots straight into R.pipe.

Syntax

Call R.findLast. Start with this line.

Ramda
R.findLast(pred, list)
CallWhat it does
R.findLast(pred, list)Primary signature.
R.findLast(...)Call the list helper.

Prefer import { findLast } from "ramda" when you want a named import.

Library declarations
Ramda
R.findLast(pred, list)

Parameters

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

Return Value

Return ValueDescription
*The last passing item itself (not a copy), or undefined

Ramda Examples

Example 1 — Official Samples vs R.find

Two objects match. findLast and find return different ones.

Ramda
const xs = [{ a: 1, b: 0 }, { a: 1, b: 1 }];

console.log(R.findLast(R.propEq(1, "a"))(xs));
// → { a: 1, b: 1 }

console.log(R.findLast(R.propEq(4, "a"))(xs));
// → undefined

console.log(R.find(R.propEq(1, "a"))(xs));
// → { a: 1, b: 0 }
Try It Yourself

How It Works

  1. Build the test. R.propEq(1, "a") checks whether obj.a equals 1. Both objects pass.
  2. From the right. findLast checks {a: 1, b: 1} first, it passes, and the search stops.
  3. Miss. No object has a: 4, so the result is undefined.
  4. From the left. R.find meets {a: 1, b: 0} first. The b value shows which one you got.

Example 2 — The Latest Matching Event

In a time-ordered log, the last match is the most recent one.

Ramda
const events = [
  { type: "login",  at: "09:00" },
  { type: "click",  at: "09:05" },
  { type: "login",  at: "13:30" },
  { type: "logout", at: "17:00" }
];

const lastLogin = R.findLast(R.propEq("login", "type"), events);

console.log(lastLogin.at);
// → 13:30
Try It Yourself

How It Works

  1. The test. R.propEq("login", "type") passes for events whose type is "login".
  2. From the end. logout fails, then the 13:30 login passes, and the search stops.
  3. Skipped. The 09:00 login is never checked.
  4. Order matters. “Last” means last in the list. This only equals “latest” because the log is sorted by time.

Example 3 — The Last Stable Version

Skip pre-release tags like -beta and -rc.

Ramda
const versions = ["1.0.0", "1.1.0-beta", "1.1.0", "2.0.0-rc.1"];

const isStable = v => !R.includes("-", v);

console.log(R.findLast(isStable, versions));
// → 1.1.0
Try It Yourself

How It Works

  1. The test. R.includes("-", v) is true for pre-releases, and the ! flips it to mean “stable”.
  2. From the end. "2.0.0-rc.1" contains a dash, so it fails.
  3. Match. "1.1.0" has no dash, so it passes and the search stops.
  4. Result. The newest stable release in this sorted list is 1.1.0.

Example 4 — findLast vs Reverse or Filter

Three ways to get the last OK reading. All give the same answer, but only one avoids extra work.

Ramda
const readings = [
  { temp: 21, ok: true },
  { temp: 99, ok: false },
  { temp: 22, ok: true },
  { temp: 0,  ok: false }
];
const isOk = R.propEq(true, "ok");

console.log(R.findLast(isOk, readings));
console.log(R.find(isOk, R.reverse(readings)));
console.log(R.last(R.filter(isOk, readings)));
// → { temp: 22, ok: true }   (all three)
Try It Yourself

How It Works

  1. findLast. It checks temp: 0, then temp: 22, and stops after 2 tests with no copy.
  2. Reverse + find. R.reverse first copies all 4 readings into a new array, then searches it.
  3. Filter + last. This tests all 4 readings, builds an array of matches, then takes its last item.
  4. Pick findLast. It gives the same result with the least work and states the intent most clearly.

Example 5 — Safe Default in a Pipeline

Get the latest error message, or "none" when there are no errors.

Ramda
const lastError = R.pipe(
  R.findLast(R.propEq("error", "level")),
  R.propOr("none", "msg")
);

const logs = [
  { level: "error", msg: "disk full" },
  { level: "info",  msg: "retrying" },
  { level: "error", msg: "network down" }
];

console.log(lastError(logs));
// → network down

console.log(lastError([{ level: "info", msg: "ok" }]));
// → none
Try It Yourself

How It Works

  1. Curried step. R.findLast(R.propEq("error", "level")) has its test but no list yet.
  2. Pipe. R.pipe runs the search, then passes the found log (or undefined) to the next step.
  3. Safe read. R.propOr("none", "msg") returns msg, or "none" when given undefined.
  4. Result. The newest error is network down. The info-only list has no errors, so you get none.

Browser & Runtime Support

R.findLast 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.findLast (Chrome 97+, Firefox 104+, Safari 15.4+, Node.js 18+). It runs anywhere Ramda runs.

✓ Stable · Ramda 0.1.1+

R.findLast()

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.findLast Ramda 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 findLast. The labs on this page use [email protected] from a CDN.

Frequently Asked Questions

R.findLast(pred, list) searches from the right and returns the last item for which pred returns a truthy value, or undefined if no item passes. Docs sample: with xs = [{a: 1, b: 0}, {a: 1, b: 1}], R.findLast(R.propEq(1, 'a'))(xs) //=> {a: 1, b: 1}.
Both return one matching item or undefined. R.find scans left to right and returns the first match. R.findLast scans right to left and returns the last match. They only differ when more than one item passes.
Both return the last match or undefined. The native method arrived in ES2023 (Chrome 97, Firefox 104, Safari 15.4, Node.js 18), while R.findLast works in any engine Ramda supports. It is also curried and data-last, so R.findLast(pred) is reusable in R.pipe.
undefined, both for an empty list and when no item passes. Add a fallback with R.defaultTo or R.propOr if you need a value.
R.addIndex counts calls, starting at 0. R.findLast calls the test from the right, so the last item is labelled index 0. Use R.findLastIndex when you need the real position.
No. R.findLast has been part of Ramda since v0.1.1 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.findLastIndex()

Learn how to get the position of the last item that passes a test.

R.findLastIndex() 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