Ramda.js R.hasIn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

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)
CallWhat 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

ParameterDescription
propRequired. 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.
objRequired. Object. The record to query. null and undefined yield false.

Return Value

Return ValueDescription
Booleantrue 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.

Example 1 — Official Rectangle

Own width and prototype area both succeed.

Ramda
function Rectangle(width, height) {
  this.width = width;
  this.height = height;
}
Rectangle.prototype.area = function () {
  return this.width * this.height;
};

const square = new Rectangle(2, 2);
R.hasIn('width', square);
//=> true
R.hasIn('area', square);
//=> true
Try It Yourself

How It Works

width is assigned on the instance. area is on Rectangle.prototype. in finds both. That is the docs sample from ramdajs.com.

Example 2 — vs R.has

hasIn sees the prototype. has does not. Empty objects still inherit toString.

Ramda
R.hasIn('area', square);
//=> true
R.has('area', square);
//=> false

R.hasIn('toString', {});
//=> true
R.has('toString', {});
//=> false
Try It Yourself

How It Works

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.

Ramda
const proto = { role: 'dev' };
const child = Object.create(proto);
child.name = 'Ada';

R.hasIn('name', child);
//=> true
R.hasIn('role', child);
//=> true
R.has('role', child);
//=> false

R.hasIn('missing', { missing: undefined });
//=> true
Try It Yourself

How It Works

Existence is not truthiness. { missing: undefined } still has the key. Object.create puts role on the prototype, so hasIn says yes and has says no.

Example 4 — Null and filter

null is false, not a throw. Map a curried hasIn('area') over mixed shapes.

Ramda
R.hasIn('area', null);
//=> false
R.hasIn('area', undefined);
//=> false

const hasArea = R.hasIn('area');
R.filter(hasArea, [square, { width: 1 }]);
//=> [square]
Try It Yourself

How It Works

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.

Ramda
const squareHas = R.hasIn(R.__, square);
squareHas('area');
//=> true
squareHas('z');
//=> false

R.hasPath(['user', 'name'], { user: { name: 'Ada' } });
//=> true
R.hasIn('user.name', { user: { name: 'Ada' } });
//=> false
Try It Yourself

How It Works

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.

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 Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All 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.

Continue to R.hasPath()

Learn how to test a nested own path on an object using Ramda R.hasPath().

R.hasPath() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful