Ramda.js R.where() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.where() answers a spec question: does this object pass every named predicate? You pass a spec object whose own values are functions, then the test object. You get a boolean. Extra keys on the test object do not matter. A missing spec key is still tested, with undefined. Native JavaScript would write several if checks. where names those checks once, stays data-last, and curries, so R.where(spec) is already a function of one object — ready for R.filter and R.find.

The official sample is the whole idea. Four predicates must all pass: a equals 'foo', b is not 'bar', x is greater than 10, y is less than 20. Only the first docs row succeeds. Need literals instead of functions? That is R.whereEq. Need any one predicate to pass? That is R.whereAny. Need one key only? That is R.propSatisfies. Previous Object helper is R.view. Next is R.whereAny.

Syntax

Call R.where. Start with this line.

Ramda
R.where(spec, testObj)
CallWhat it does
R.where(spec, testObj)Primary signature.
R.where(...)Call the object helper.

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

Library declarations
Ramda
R.where(spec, testObj)

Parameters

ParameterDescription
specRequired. Object. Own properties must be predicate functions. Each is called with testObj[key]. Inherited spec keys are skipped.
testObjRequired. Object. The record under test. Extra keys are ignored. A missing spec key reads as undefined.

Return Value

Return ValueDescription
Booleantrue when every own spec predicate returns a truthy leftover. Otherwise false. Neither object is mutated. An empty spec yields true.

Ramda Examples

📚 Getting Started

The official Ramda object sample, then the same idea compared with whereEq and whereAny.

Example 1 — Official pred

Four predicates must all pass. Extra keys would be ignored. One failed field is enough to yield false.

Ramda
const pred = R.where({
  a: R.equals('foo'),
  b: R.complement(R.equals('bar')),
  x: R.gt(R.__, 10),
  y: R.lt(R.__, 20)
});

pred({a: 'foo', b: 'xxx', x: 11, y: 19});
//=> true

pred({a: 'xxx', b: 'xxx', x: 11, y: 19});
//=> false

pred({a: 'foo', b: 'bar', x: 11, y: 19});
//=> false

pred({a: 'foo', b: 'xxx', x: 10, y: 19});
//=> false

pred({a: 'foo', b: 'xxx', x: 11, y: 20});
//=> false
Try It Yourself

How It Works

b: R.complement(R.equals('bar')) means b must not be 'bar'. x must be strictly greater than 10, so 10 fails. y must be strictly less than 20, so 20 fails. That is the docs sample from ramdajs.com.

Example 2 — vs whereEq, whereAny, and propSatisfies

Same row. where needs functions and AND. whereEq uses literals. whereAny is OR. propSatisfies tests one key.

Ramda
const row = { a: 1, b: 2, extra: true };

R.where({ a: R.equals(1), b: R.equals(2) }, row);
//=> true

R.whereEq({ a: 1, b: 2 }, row);
//=> true

R.whereAny({ a: R.equals(9), b: R.equals(2) }, row);
//=> true

R.propSatisfies(R.equals(1), 'a', row);
//=> true
Try It Yourself

How It Works

extra is ignored by all three spec helpers. whereAny is true because b matches even though a does not. Prefer whereEq when every spec leftover is a value. Prefer where when you need ranges, complements, or other functions.

📈 Practical Patterns

Extra keys, missing fields, an empty spec, then filter and find, then why literals belong on whereEq.

Example 3 — Extra Keys, Missing Keys, Empty Spec

Extra fields do not fail the spec. A missing field still runs the predicate with undefined. An empty spec never loops, so the leftover is true.

Ramda
const adult = R.where({ age: R.gte(R.__, 18) });

adult({ name: 'Ada', age: 21 });
//=> true

adult({ name: 'Ada' });
//=> false

R.where({}, { x: 1 });
//=> true
Try It Yourself

How It Works

R.gte(R.__, 18)(undefined) is false, so a missing age fails. R.where({}, null) is also true, because the loop never reads the test object. A non-empty spec on null throws.

Example 4 — Curry, Filter, and Find

Fill the spec to get a predicate of one row. Keep matching tickets. Find the first match.

Ramda
const pred = R.where({
  status: R.equals('open'),
  score: R.gt(R.__, 10)
});

const rows = [
  { id: 1, status: 'open', score: 11 },
  { id: 2, status: 'done', score: 20 },
  { id: 3, status: 'open', score: 4 }
];

R.filter(pred, rows);
//=> [{ id: 1, status: 'open', score: 11 }]

R.find(pred, rows);
//=> { id: 1, status: 'open', score: 11 }
Try It Yourself

How It Works

Because where is arity 2, filling spec leaves a function of one object for R.filter and R.find. Row 2 fails status. Row 3 fails score. That is the docs use case: declarative constraints for list helpers.

Example 5 — Literals Belong on whereEq

A number in the spec is not a predicate. Wrap it with R.equals, or switch to whereEq.

Ramda
R.where({ a: R.equals(1) }, { a: 1 });
//=> true

R.whereEq({ a: 1 }, { a: 1 });
//=> true

typeof 1 === 'function';
//=> false
Try It Yourself

How It Works

Before v0.13.0, R.where({a: 1}) treated non-functions as equality checks. That mixed style moved to R.whereEq. Today R.where({ a: 1 }, { a: 1 }) throws because 1 is not callable. The third line is a reminder: spec values must be functions.

Browser Support

R.where() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.1.1+ · Any JS runtime

Ramda.js R.where()

Load Ramda 0.1.1 or later via CDN or npm, then call R.where with a spec of predicates and a test object. No extra browser API is required.

100% With Ramda 0.1.1+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.where() Universal

Bottom line: Safe in any project that includes Ramda 0.1.1 or later. Spec values must be functions from 0.13.0 onward. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.where(spec, testObj) returns true when every own property on spec is a predicate that returns true for testObj of that same key. Extra keys on the test object are ignored. Added in v0.1.1. Since v0.13.0 every spec value must be a function.
const pred = R.where({ a: R.equals('foo'), b: R.complement(R.equals('bar')), x: R.gt(R.__, 10), y: R.lt(R.__, 20) }). pred({a:'foo', b:'xxx', x:11, y:19}) is true. The other four official rows are false.
where runs predicate functions and requires all of them to pass (AND). whereEq compares spec values with R.equals instead of calling functions. whereAny is the OR cousin: one passing predicate is enough.
The predicate still runs, with undefined. R.where({ age: R.gte(R.__, 18) }, {}) is false. An empty spec {} returns true, even for null, because no predicates run.
No. Spec values must be functions. R.where({ a: 1 }, { a: 1 }) throws because 1 is not callable. Use R.whereEq({ a: 1 }, obj) or wrap with R.equals.
No. R.where is a stable Ramda object helper from v0.1.1. It is not deprecated, experimental, or non-standard.

Continue to R.whereAny()

Learn how to pass when any one spec predicate is true using Ramda R.whereAny().

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