Ramda’s R.hasPath() answers a nested question: does this path of own keys exist? You pass a path array, then the object. You get a boolean. Missing a segment is false. A key whose value is undefined is still present. Inherited keys at any step fail.
The official sample is the whole idea. R.hasPath(['a', 'b'], {a: {b: 2}}) is true. The same path is true when b is undefined, false when b is missing, and false on {}. Native JavaScript has no one-liner for this: you would loop hasOwnProperty (or Object.hasOwn) at each step. Need one own key? That is R.has. Need one prototype key? That is R.hasIn. Need the value at the path? That is R.path — and undefined there is ambiguous. Lodash _.has often treats a string as a path; Ramda wants an array of keys.
Syntax
Call R.hasPath. Start with this line.
Ramda
R.hasPath(path, obj)
Call
What it does
R.hasPath(path, obj)
Primary signature.
R.hasPath(...)
Call the object helper.
Prefer import { hasPath } from "ramda" when you want a named import.
Library declarations
Ramda
R.hasPath(path, obj)
Parameters
Parameter
Description
path
Required. Array of keys. Own keys to walk, such as ['a', 'b'] or ['items', 1]. A dotted string is a literal key, not a nested path. An empty array is always ...
obj
Required. Object. The record to query. null and undefined yield false.
Return Value
Return Value
Description
Boolean
true when every segment is an own property. Otherwise false. The object is not mutated.
Ramda Examples
📚 Getting Started
The official nested path sample, then has and hasIn as one-key cousins.
Example 1 — Official Nested Path
Present keys succeed, including undefined. Missing keys and empty objects fail.
R.has is hasPath with a one-item array. After user is found, role lives on the prototype, so hasPath says no. R.hasIn uses in on that one object and says yes.
📈 Practical Patterns
Array indexes, empty paths, a null-safe filter, then path as the value-reading cousin.
Example 3 — Arrays, Empty Path, Dotted String
Integer segments target array indexes. An empty path is false. A dotted string is one literal key.
Dense arrays own their index keys. Index 9 is missing. The source returns false when the path length is 0. 'user.name' would only match a key whose name contains a dot.
Example 4 — Null and filter
null is false, not a throw. Fill the path to keep rows that own a nested key.
Both R.path calls print undefined. Only hasPath tells them apart. Next Object helper is invert.
Compatibility
Browser Support
R.hasPath() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.
✓ Ramda 0.26.0+ · Any JS runtime
Ramda.js R.hasPath()
Load Ramda 0.26.0 or later via CDN or npm, then call R.hasPath with a path array and an object. No extra browser API is required.
100%With Ramda 0.26.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.hasPath()Universal
Bottom line: Safe in any project that includes Ramda 0.26.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.hasPath(path, obj) returns true when every segment of path is an own property, walking nested objects and arrays. Inherited keys at any step fail. Added in v0.26.0.
R.hasPath(['a','b'], {a:{b:2}}) is true. The same path is true when b is undefined, false when b is missing, and false on {}.
has is a one-key own check. hasIn also walks the prototype for that one key. hasPath walks a path array and uses an own-property check at every step. R.has(prop, obj) is implemented as R.hasPath([prop], obj).
Yes. {a:{b:undefined}} still has own key b, so R.hasPath(['a','b'], obj) is true. Existence is not truthiness.
An empty path [] is false. R.hasPath(['a'], null) and R.hasPath(['a'], undefined) are false. A string such as 'a.b' is one literal key, not a nested path.
No. R.hasPath is a stable Ramda object helper from v0.26.0. It is not deprecated, experimental, or non-standard.