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)
Call
What 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
Parameter
Description
pred
Required. Function. Called as pred(value, key, obj). A truthy leftover keeps that property. You may ignore extra arguments.
obj
Required. Object. The source. The source is never mutated. Nested values stay shared by reference.
Return Value
Return Value
Description
Object
A 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.
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.
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.
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.
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.
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.