Ramda.js R.endsWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A check that returns true when a string ends with a substring, or a list ends with a sublist. Items are compared with R.equals, so objects match by value. Part of Ramda List since v0.24.0 (stable — not deprecated, experimental, or non-standard).

Why not the native method? "app.js".endsWith(".js") only works on strings and must be called on the data. R.endsWith(".js") is curried and data-last, so it drops straight into R.filter — and it works on arrays too.

Syntax

Call R.endsWith. Start with this line.

Ramda
R.endsWith(suffix, list)
CallWhat it does
R.endsWith(suffix, list)Primary signature.
R.endsWith(...)Call the list helper.

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

Library declarations
Ramda
R.endsWith(suffix, list)

Parameters

ParameterDescription
suffixRequired. The ending to look for (string or array)
listRequired. The string or array to check

Return Value

Return ValueDescription
*true or false

Ramda Examples

Example 1 — Official String Samples

Check the last character of a string.

Ramda
console.log(R.endsWith("c", "abc")); // → true
console.log(R.endsWith("b", "abc")); // → false
Try It Yourself

How It Works

  1. Suffix first. "c" is what we look for; "abc" is the data.
  2. Cut the tail. The suffix has 1 character, so Ramda takes the last 1 character: "c".
  3. Compare. "c" equals "c" → true.
  4. Second call. The tail is still "c", which is not "b" → false.

Example 2 — Arrays and Multi-Item Suffixes

The official array samples, plus a two-item suffix where order matters.

Ramda
console.log(R.endsWith(["c"], ["a", "b", "c"])); // → true
console.log(R.endsWith(["b"], ["a", "b", "c"])); // → false

console.log(R.endsWith([2, 3], [1, 2, 3]));      // → true
console.log(R.endsWith([3, 2], [1, 2, 3]));      // → false
Try It Yourself

How It Works

  1. Array suffix. For lists, the suffix is a list too — ["c"], not "c".
  2. One item. The last item of ["a", "b", "c"] is ["c"] → matches ["c"], not ["b"].
  3. Two items. The last two of [1, 2, 3] are [2, 3] → true.
  4. Order matters. [3, 2] has the same numbers in a different order → false.

Example 3 — Filter Files by Extension

Curry endsWith into a test and pass it to R.filter.

Ramda
const files = ["logo.png", "app.js", "photo.png", "notes.txt"];

const isPng = R.endsWith(".png");

console.log(R.filter(isPng, files));
// → ["logo.png", "photo.png"]
Try It Yourself

How It Works

  1. Curry. R.endsWith(".png") gets only the suffix, so it returns a function waiting for the file name.
  2. Filter. R.filter calls isPng on each name.
  3. Check. "logo.png" and "photo.png" end with ".png" → kept.
  4. Drop. "app.js" and "notes.txt" do not → removed.

Example 4 — Objects Match by Value

Check the last item in a cart, even though it is a different object.

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

console.log(R.endsWith([{ id: 2 }], cart));  // → true
console.log(R.last(cart) === { id: 2 });     // → false
Try It Yourself

How It Works

  1. Tail. Ramda takes the last item of cart: [{ id: 2 }].
  2. Deep compare. R.equals checks contents, and both objects have id: 2 → true.
  3. Plain ===. R.last(cart) and the new { id: 2 } are two different objects in memory → false.
  4. Takeaway. You can check endings with fresh object literals — no need to keep the original reference.

Example 5 — Case Sensitivity and Several Endings

Accept .jpg or .png in any letter case.

Ramda
const isImage = R.anyPass([R.endsWith(".jpg"), R.endsWith(".png")]);

console.log(R.endsWith(".png", "PHOTO.PNG"));   // → false
console.log(isImage(R.toLower("PHOTO.PNG")));   // → true
console.log(isImage("notes.txt"));              // → false
Try It Yourself

How It Works

  1. Case-sensitive. ".PNG" is not ".png", so the first check is false.
  2. Normalize first. R.toLower turns "PHOTO.PNG" into "photo.png".
  3. Any of several. R.anyPass returns true if either endsWith test passes → true.
  4. No match. "notes.txt" fails both tests → false.

Browser & Runtime Support

R.endsWith is a Ramda List helper since v0.24.0. It is built from R.takeLast and R.equals, not the native String.prototype.endsWith, so it runs anywhere Ramda runs — browsers via CDN or bundler, and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.24.0+

R.endsWith()

Support depends on the Ramda version you load, not on a browser feature. Load Ramda 0.24.0 or later; older versions do not have endsWith.

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.endsWith Ramda 0.24.0+

Bottom line: Safe for production in any modern browser or JavaScript runtime once Ramda 0.24.0+ is loaded. The labs on this page use [email protected] from a CDN.

Frequently Asked Questions

R.endsWith(suffix, list) returns true when a string ends with the given substring, or when a list ends with the given sublist. Docs samples: R.endsWith('c', 'abc') //=> true and R.endsWith(['c'], ['a', 'b', 'c']) //=> true.
Ramda puts the data last so you can curry: R.endsWith('.png') is a ready-made test you can pass to R.filter. This is the opposite order of the native 'abc'.endsWith('c') method call.
No — that returns false. For lists the suffix must also be a list: R.endsWith([3], [1, 2, 3]) //=> true. A string suffix against an array (or the reverse) is also false.
It uses R.equals, a deep, value-based comparison. So R.endsWith([{ id: 2 }], [{ id: 1 }, { id: 2 }]) is true even though the two { id: 2 } objects are different references.
An empty suffix ('' or []) always returns true. A suffix longer than the list always returns false. The check is also case-sensitive.
No. R.endsWith has been part of Ramda since v0.24.0 and is stable — not deprecated, experimental, or non-standard.

Next: R.filter()

Learn how to keep only the items that pass a test — the natural partner for R.endsWith.

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