Ramda’s R.hasIn() answers a chain question: does this name exist on the object or anywhere up its prototype? You pass the property name, then the object. You get a boolean. Own keys count. Inherited keys count. The value can be a function on Rectangle.prototype or undefined on the instance.
The official sample is the whole idea. A Rectangle instance owns width and height. area is a method on the prototype. R.hasIn('width', square) and R.hasIn('area', square) are both true. Native JavaScript is 'area' in square. That throws on null. hasIn returns false instead. Need own keys only? That is R.has. Nested paths? That is R.hasPath. Lodash _.hasIn often treats a string as a path; Ramda’s hasIn is one key and the in operator.
Syntax
Call R.hasIn. Start with this line.
Ramda
R.hasIn(prop, obj)
Call
What it does
R.hasIn(prop, obj)
Primary signature.
R.hasIn(...)
Call the object helper.
Prefer import { hasIn } from "ramda" when you want a named import.
Library declarations
Ramda
R.hasIn(prop, obj)
Parameters
Parameter
Description
prop
Required. String (or key). The name to look for on the object or its prototype chain. 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 prop in obj would be true. Otherwise false. The object is not mutated.
Ramda Examples
📚 Getting Started
The official Rectangle sample, then the same instance compared with own-only has.
R.has uses an own-property check. hasIn uses in. JSON field checks almost always want has. Class methods almost always want hasIn. toString is the everyday reminder that every plain object inherits names from Object.prototype.
📈 Practical Patterns
Object.create defaults, a null-safe filter, then a placeholder and hasPath as the nested cousin.
Example 3 — Object.create and Undefined
Inherited defaults match hasIn. Own keys set to undefined also match. has still skips the prototype.
Native 'area' in null throws. hasIn returns false first. The Try-it lab maps surviving shapes to width, so you see [2] instead of a Rectangle dump. R.filter keeps only the instance that inherited area.
Example 5 — Placeholder vs hasPath
Fill the object with R.__. Nested own keys need a path array, not a dotted string.
R.__ holds the key slot open, the same habit as the official has sample. hasPath walks two own keys. 'user.name' would only match a literal key with a dot in the name. Next Object helper is hasPath.
Compatibility
Browser Support
R.hasIn() 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.hasIn()
Load Ramda 0.7.0 or later via CDN or npm, then call R.hasIn 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.hasIn()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.hasIn(prop, obj) returns true when prop exists on obj or anywhere on its prototype chain. It is the in operator with a nil guard. Added in v0.7.0.
A Rectangle instance has own keys width and height, and area on the prototype. R.hasIn('width', square) and R.hasIn('area', square) are both true.
has checks own properties only. hasIn also sees inherited keys, so R.has('area', square) is false while R.hasIn('area', square) is true. R.has('toString', {}) is false; R.hasIn('toString', {}) is true.
Yes. The in operator counts the key even when the value is undefined. Existence is not truthiness.
R.hasIn('a', null) and R.hasIn('a', undefined) are false. They do not throw. The source returns false when isNil(obj) is true, because prop in null would throw.
No. R.hasIn is a stable Ramda object helper from v0.7.0. It is not deprecated, experimental, or non-standard.