Ramda.js R.filter() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

A helper that keeps only the members that pass a test and returns them in a new array — or a new object, if you pass a plain object. The original is never changed. Part of Ramda List since v0.1.0 (stable — not deprecated, experimental, or non-standard).

Why not the native method? Array.prototype.filter must be called on the data. R.filter(isEven) is curried and data-last, so it becomes a reusable step for R.pipe — and it works on objects too.

Syntax

Call R.filter. Start with this line.

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

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

Library declarations
Ramda
R.filter(pred, data)

Parameters

ParameterDescription
predRequired. value → Boolean — truthy means "keep"
dataRequired. An array, a plain object, or anything with a filter method

Return Value

Return ValueDescription
*A new array or object with only the passing members

Ramda Examples

Example 1 — Official Array Sample

Keep the even numbers.

Ramda
const isEven = n => n % 2 === 0;

console.log(R.filter(isEven, [1, 2, 3, 4]));
// → [2, 4]
Try It Yourself

How It Works

  1. The test. isEven returns true when the remainder after dividing by 2 is 0.
  2. Test each. R.filter calls isEven on 1, 2, 3, and 4 in order.
  3. Keep the passes. Only 2 and 4 return true.
  4. New array. The result [2, 4] is a fresh array; the original list is unchanged.

Example 2 — Filtering a Plain Object

The official object sample, plus a price list.

Ramda
const isEven = n => n % 2 === 0;

console.log(R.filter(isEven, { a: 1, b: 2, c: 3, d: 4 }));
// → { b: 2, d: 4 }

const prices = { pen: 2, book: 15, bag: 40 };

console.log(R.filter(p => p >= 10, prices));
// → { book: 15, bag: 40 }
Try It Yourself

How It Works

  1. Values are tested. For an object, the test receives each value (1, 2, …), not the key.
  2. Keys stay attached. Passing values keep their keys, so b: 2 and d: 4 survive.
  3. Prices. 15 and 40 are at least 10; pen: 2 is dropped.
  4. Same type out. An object in gives a new object out — not an array.

Example 3 — Filter Records by a Property

Keep only the paid orders with R.propEq.

Ramda
const orders = [
  { id: 1, status: "paid" },
  { id: 2, status: "open" },
  { id: 3, status: "paid" }
];

const paid = R.filter(R.propEq("paid", "status"), orders);

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

How It Works

  1. Build the test. R.propEq("paid", "status") returns order => order.status === "paid" (using R.equals).
  2. Argument order. Since Ramda v0.29 the value comes first, then the property name.
  3. Filter. Orders 1 and 3 are paid → kept; order 2 is open → dropped.
  4. Show ids. R.pluck("id") turns the kept orders into [1, 3].

Example 4 — Several Rules with R.where

Keep users who are active and at least 18.

Ramda
const users = [
  { name: "Ada", age: 36, active: true },
  { name: "Lin", age: 17, active: true },
  { name: "Bo",  age: 42, active: false }
];

const isAdultActive = R.where({
  active: R.equals(true),
  age: age => age >= 18
});

console.log(R.pluck("name", R.filter(isAdultActive, users)));
// → ["Ada"]
Try It Yourself

How It Works

  1. One rule per field. R.where takes an object of tests, one for each property.
  2. All must pass. It returns true only when every field test passes.
  3. Check each user. Ada passes both; Lin fails the age rule; Bo fails the active rule.
  4. Result. Only Ada is kept, so the names are ["Ada"].

Example 5 — Curried Filter in a Pipeline

Build a reusable “active user names” function without mentioning the data.

Ramda
const users = [
  { name: "Ada", active: true },
  { name: "Lin", active: true },
  { name: "Bo",  active: false }
];

const activeNames = R.pipe(
  R.filter(R.prop("active")),
  R.pluck("name")
);

console.log(activeNames(users));
// → ["Ada", "Lin"]
Try It Yourself

How It Works

  1. Curried step. R.filter(R.prop("active")) has its test but no data yet — it waits for a list.
  2. Truthy test. R.prop("active") returns each user’s active value, which is already true / false.
  3. Pipe. R.pipe runs the filter first, then hands the result to R.pluck("name").
  4. Reuse. activeNames works on any user list → ["Ada", "Lin"].

Browser & Runtime Support

R.filter is one of Ramda’s original List helpers, available since v0.1.0. It uses its own loop rather than the native Array.prototype.filter, so it runs anywhere Ramda runs — browsers via CDN or bundler, and Node.js / Bun / Deno with npm install ramda.

✓ Stable · Ramda 0.1.0+

R.filter()

Support depends on the Ramda version you load, not on a browser feature. Your own test must also be valid in that runtime — e.g. 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.filter Ramda 0.1.0+

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.filter(pred, data) returns a new array (or object) containing only the members for which pred returns a truthy value. Docs samples: R.filter(isEven, [1, 2, 3, 4]) //=> [2, 4] and R.filter(isEven, { a: 1, b: 2, c: 3, d: 4 }) //=> { b: 2, d: 4 }.
R.filter is curried and data-last, so R.filter(isEven) is a reusable function for R.pipe. It also filters plain objects by value. Unlike the native method, the predicate receives only the value — no index or array.
Yes. For a plain object it tests each own value and returns a new object with the passing keys. To filter by key, or by key and value together, use R.pickBy.
Wrap it with R.addIndex: R.addIndex(R.filter)((x, i) => i % 2 === 0, list). Plain R.filter passes only the value.
R.reject keeps the items that fail the test. R.partition returns both groups at once: [passing, failing].
No. R.filter has been part of Ramda since v0.1.0 and is stable — not deprecated, experimental, or non-standard.

Next: R.find()

Learn how to return just the first item that passes a test.

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