Ramda.js R.has() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

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

ParameterDescription
propRequired. String (or key). The own property name to look for. 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 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.

Ramda
const hasName = R.has('name');

hasName({name: 'alice'});
//=> true

hasName({name: 'bob'});
//=> true

hasName({});
//=> false
Try It Yourself

How It Works

Because has is arity 2, filling 'name' leaves a predicate. alice and bob both own name. {} does not. That is the first docs sample from ramdajs.com.

Example 2 — Official R.__

The placeholder keeps a hole for the key so you can reuse one object.

Ramda
const point = {x: 0, y: 0};
const pointHas = R.has(R.__, point);

pointHas('x');
//=> true

pointHas('y');
//=> true

pointHas('z');
//=> false
Try It Yourself

How It Works

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.

Ramda
R.has('missing', { missing: undefined });
//=> true

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

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

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

'role' in child;
//=> true
Try It Yourself

How It Works

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.

Ramda
R.has('a', null);
//=> false

R.has('a', undefined);
//=> false

R.filter(R.has('id'), [{ id: 1 }, { n: 'x' }, { id: 2 }]);
//=> [{ id: 1 }, { id: 2 }]
Try It Yourself

How It Works

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.

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.has('area', square);
//=> false

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

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

R.has('user.name', { user: { name: 'Ada' } });
//=> false
Try It Yourself

How It Works

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

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 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.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.

Continue to R.hasIn()

Learn how to test a property on an object or its prototype chain using Ramda R.hasIn().

R.hasIn() 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