Ramda’s R.prop() answers a one-field question: what is the value at this name? You pass a key (or an integer index), then an object. You get that value, or undefined if it is missing. Native JavaScript is obj[p], but that throws on null and is awkward to drop into map. prop is data-last, so R.prop('name') is already a function of one object — ready for R.map, R.pipe, or R.compose.
The official sample is the whole idea. R.prop('x', {x: 100}) is 100. R.prop('x', {}) is undefined. R.prop(0, [100]) is 100. Then the curry payoff: R.compose(R.inc, R.prop('x'))({ x: 3 }) is 4. Need a nested walk? That is R.path. Need one column from many rows? That is R.pluck (map of prop). Need several keys from one object as an array? That is R.props. Need a default when the value is undefined? Next Object helper is R.propOr.
Syntax
Call R.prop. Start with this line.
Ramda
R.prop(p, obj)
Call
What it does
R.prop(p, obj)
Primary signature.
R.prop(...)
Call the object helper.
Prefer import { prop } from "ramda" when you want a named import.
Library declarations
Ramda
R.prop(p, obj)
Parameters
Parameter
Description
p
Required. String, Int, or Symbol. The property name or array index. An integer uses nth (negative indexes count from the end). Other values use obj[p].
obj
Required. Object or Array. The value to query. null and undefined return undefined instead of throwing. The source is never mutated.
Return Value
Return Value
Description
Any or undefined
The value at that key or index. A missing name is undefined. Falsy stored values such as 0 and false are returned as-is — they are not treated as missing.
Ramda Examples
📚 Getting Started
The official getter, then integer indexes on arrays.
Example 1 — Official x Getter
Read x when it exists. A missing name is undefined, not a throw.
Native null.x throws. prop checks obj == null first. Need a fallback for missing keys? That is R.propOr.
Compatibility
Browser Support
R.prop() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.1.0+ · Any JS runtime
Ramda.js R.prop()
Load Ramda 0.1.0 or later via CDN or npm, then call R.prop with a key and an object. No extra browser API is required.
100%With Ramda 0.1.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.prop()Universal
Bottom line: Safe in any project that includes Ramda 0.1.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.prop(p, obj) returns the value at that property (or array index) if it exists. Missing keys, and null or undefined objects, yield undefined. Added in v0.1.0. The original object is not mutated.
R.prop('x', {x: 100}) is 100. R.prop('x', {}) is undefined. R.prop(0, [100]) is 100. R.compose(R.inc, R.prop('x'))({ x: 3 }) is 4.
prop reads one key on one object (or one index). path walks a nested list of keys. pluck maps prop over a list. When p is an integer, prop delegates to nth, including negative indexes.
A missing name is undefined. R.prop('x', null) and R.prop('x', undefined) also return undefined instead of throwing.
No. It only reads. Nested objects you receive are the same reference as on the source.
No. R.prop is a stable Ramda object helper from v0.1.0. It is not deprecated, experimental, or non-standard.