Ramda’s R.has() answers an existence question: does this object own this key? You pass the property name, then the object. You get a boolean. The value can be 0, '', or even undefined — if the key is own, the answer is true. Inherited prototype keys do not count.
The official samples are the whole idea. const hasName = R.has('name') is already a function of one object, ready for R.filter. R.has(R.__, point) fills the object first so you can ask several keys of the same point. Native JavaScript’s cousin is Object.prototype.hasOwnProperty.call(obj, prop) (or Object.hasOwn in modern engines). The in operator is closer to R.hasIn: it also sees the prototype. Nested paths belong on R.hasPath. Lodash _.has walks paths and treats inherited keys differently by version, so Ramda’s own-key has is the clearer contract.
Syntax
Call R.has. Start with this line.
Ramda
R.has(prop, obj)
Call
What it does
R.has(prop, obj)
Primary signature.
R.has(...)
Call the object helper.
Prefer import { has } from "ramda" when you want a named import.
Library declarations
Ramda
R.has(prop, obj)
Parameters
Parameter
Description
prop
Required. String (or key). The own property name to look for. A dotted string is a literal key, not a nested path.
obj
Required. Object. The record to query. null and undefined yield false.
Return Value
Return Value
Description
Boolean
true when obj has that own property. Otherwise false. Neither the object nor the key is rewritten.
Ramda Examples
📚 Getting Started
Both official Ramda samples: a curried key predicate, then a placeholder that fills the object first.
Example 1 — Official hasName
Fill the key to get a function of one object. Empty objects fail.
Data last usually means object last. When the object is known and the key varies, R.__ holds the first slot open. x: 0 is still present: has does not care that the value is zero.
📈 Practical Patterns
Undefined values versus inherited keys, null-safe filter, then hasIn and hasPath as cousins.
Example 3 — Own Keys vs Inherited
A key set to undefined is still own. A prototype field is not. The in operator would see it.
Existence is not truthiness. { missing: undefined } owns the key. Object.create puts role on the prototype, so has says no and in says yes. Use hasIn when the prototype should count.
Example 4 — Null and filter
null and undefined as the object are false, not a throw. Map the predicate over rows.
Internally hasPath treats a nil object as a failed path, so you can drop has into R.filter without wrapping a try/catch. Rows without an own id are dropped.
Example 5 — hasIn and hasPath
Prototype methods need hasIn. Nested keys need a path array, not a dotted string.
area lives on Rectangle.prototype, so has is false and hasIn is true. hasPath(['user', 'name']) walks two own keys. 'user.name' would only match a literal key with a dot in the name. The docs’ see-also for has is hasPath; has is implemented as hasPath([prop], obj).
Compatibility
Browser Support
R.has() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.7.0+ · Any JS runtime
Ramda.js R.has()
Load Ramda 0.7.0 or later via CDN or npm, then call R.has with a key and an object. No extra browser API is required.
100%With Ramda 0.7.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.has()Universal
Bottom line: Safe in any project that includes Ramda 0.7.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.has(prop, obj) returns true when obj has an own property named prop. Inherited prototype keys do not count. Added in v0.7.0.
const hasName = R.has('name') is true for {name: 'alice'} and {name: 'bob'}, false for {}. With a placeholder, R.has(R.__, {x: 0, y: 0}) is true for 'x' and 'y', false for 'z'.
Yes. Own keys count even when the value is undefined. R.has checks existence, not truthiness.
has is own keys only. hasIn also walks the prototype. hasPath walks a nested path array. The in operator includes inherited keys, like hasIn.
R.has('a', null) and R.has('a', undefined) are false. They do not throw. Internally has is hasPath([prop], obj), and a nil object fails the path check.
No. R.has is a stable Ramda object helper from v0.7.0. It is not deprecated, experimental, or non-standard.