Ramda.js R.pickBy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.pickBy() answers a dynamic whitelist: which properties should the copy keep, according to this test? You pass a predicate, then the object. You get a new object with only the properties that passed. Native JavaScript has no one-liner for that; you usually write a for…in loop or Object.fromEntries(Object.entries(obj).filter(...)). pickBy is data-last, so R.pickBy((val, key) => key !== 'password') is already a function of one object — ready for R.map or R.pipe.

The official sample is the whole idea. A predicate (val, key) => key.toUpperCase() === key on {a: 1, b: 2, A: 3, B: 4} keeps {A: 3, B: 4}. The test used the key. Need a fixed list of names? That is R.pick. Need to test values on an object with own keys only? That is R.filter. Need the inverse drop? That is R.omitBy.

Syntax

Call R.pickBy. Start with this line.

Ramda
R.pickBy(pred, obj)
CallWhat it does
R.pickBy(pred, obj)Primary signature.
R.pickBy(...)Call the object helper.

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

Library declarations
Ramda
R.pickBy(pred, obj)

Parameters

ParameterDescription
predRequired. Function. Called as pred(value, key, obj). A truthy leftover keeps that property. You may ignore extra arguments.
objRequired. Object. The source. The source is never mutated. Nested values stay shared by reference.

Return Value

Return ValueDescription
ObjectA new object with only the properties that passed. If none pass, {}. Enumerable inherited properties can be copied because the walk uses for…in.

Ramda Examples

📚 Getting Started

The official key test, then the same helper on values instead of keys.

Example 1 — Official Uppercase Keys

The predicate receives (val, key). The test uses the key. Lowercase names leave.

Ramda
const isUpperCase = (val, key) => key.toUpperCase() === key;

R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4});
//=> {A: 3, B: 4}
Try It Yourself

How It Works

'a'.toUpperCase() is 'A', which is not equal to 'a', so a and b drop. 'A' already matches. That is the docs sample from ramdajs.com.

Example 2 — Keep by Value

Ignore the key. Keep numbers that are at least 2. The leftover is still an object, not an array.

Ramda
R.pickBy((val) => val >= 2, {a: 1, b: 2, c: 3, d: 4});
//=> {b: 2, c: 3, d: 4}
Try It Yourself

How It Works

Extra predicate arguments are ignored, so a one-argument test is fine. 1 >= 2 is false, so a leaves. This is the value-only cousin of the official key test.

📈 Practical Patterns

Compare pick and filter, then a curried secret strip, then mapping and inherited keys.

Example 3 — vs pick and filter

pick needs names in advance. filter on objects tests values and own keys. pickBy can test the key.

Ramda
const obj = {a: 1, b: 2, A: 3};

R.pickBy((val, key) => key === key.toUpperCase(), obj);
//=> {A: 3}

R.pick(['A'], obj);
//=> {A: 3}

R.filter((val) => val >= 2, obj);
//=> {b: 2, A: 3}
Try It Yourself

How It Works

R.filter never sees the key, so it cannot implement the official uppercase rule. Use pick when you already know ['A']. Use pickBy when the rule must look at names.

Example 4 — Curry, Strip Secrets, Shallow Copy

Fill the predicate to get a function of one object. Nested objects stay the same reference. The original still holds the password.

Ramda
const orig = { id: 7, name: 'Ada', password: 'secret', profile: { city: 'Paris' } };
const publicUser = R.pickBy((val, key) => key !== 'password');
const copy = publicUser(orig);

copy;
//=> {id: 7, name: 'Ada', profile: {city: 'Paris'}}

copy === orig;
//=> false

copy.profile === orig.profile;
//=> true
Try It Yourself

How It Works

Because pickBy is arity 2, filling pred leaves a function of one object. Nested profile is copied by reference. Clone it (or use R.clone) if later writes must not leak.

Example 5 — Map, Empty Leftover, Inherited Keys

Map a keep-rule over rows. If nothing passes, the leftover is {}. for…in can copy enumerable inherited properties; R.filter would not.

Ramda
const dropPass = R.pickBy((val, key) => key !== 'password');

R.map(dropPass, [
  { user: 'Ada', password: 'a' },
  { user: 'Bo', password: 'b' }
]);
//=> [{user: 'Ada'}, {user: 'Bo'}]

R.pickBy(R.always(false), {a: 1});
//=> {}

const proto = { inherited: 1 };
const child = Object.create(proto);
child.own = 2;
R.pickBy(R.always(true), child);
//=> {own: 2, inherited: 1}
Try It Yourself

How It Works

R.always(false) keeps nothing. Object.create puts inherited on the prototype; pickBy’s for…in still sees it. Prefer R.filter when you want own keys only.

Browser Support

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

✓ Ramda 0.8.0+ · Any JS runtime

Ramda.js R.pickBy()

Load Ramda 0.8.0 or later via CDN or npm, then call R.pickBy with a predicate and an object. No extra browser API is required.

100% With Ramda 0.8.0+
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.pickBy() Universal

Bottom line: Safe in any project that includes Ramda 0.8.0 or later. 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.pickBy(pred, obj) returns a partial copy of obj with only the properties whose predicate is true. The predicate is called as pred(value, key, obj). Added in v0.8.0. The original object is not mutated.
const isUpperCase = (val, key) => key.toUpperCase() === key; R.pickBy(isUpperCase, {a: 1, b: 2, A: 3, B: 4}) is {A: 3, B: 4}. The test uses the key, not the value.
pick keeps a fixed list of names. pickBy decides with a function of value and key. R.filter on an object tests values only and walks own keys. pickBy uses for...in, so enumerable inherited properties can be copied.
No. It always allocates a new object. Nested values are copied by reference, so the copy is shallow.
You get {}. An empty object input also yields {}.
No. R.pickBy is a stable Ramda object helper from v0.8.0. It is not deprecated, experimental, or non-standard.

Continue to R.project()

Learn how to pick the same keys from every object in a list using Ramda R.project().

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