Ramda.js R.keysIn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.keysIn() answers a chain question: which enumerable names exist on this object or anywhere up its prototype? You pass an object. You get an array of strings. Own enumerable names count. Inherited enumerable names count. Non-enumerable names such as toString do not.

The official sample is the whole idea. A constructor writes this.x. y is assigned on the prototype. R.keysIn(f) is ['x', 'y']. Native JavaScript is a for…in loop. That throws on null. keysIn does the same, because the source is that loop. Need own names only, and a quiet [] on null? That is the previous helper, R.keys. Need the values on the chain? That is R.valuesIn. Lodash _.keysIn is the same idea, often data-first.

Syntax

Call R.keysIn. Start with this line.

Ramda
R.keysIn(obj)
CallWhat it does
R.keysIn(obj)Primary signature.
R.keysIn(...)Call the object helper.

Prefer import { keysIn } from "ramda" when you want a named import.

Library declarations
Ramda
R.keysIn(obj)

Parameters

ParameterDescription
objRequired. Object. The record to inspect. Arrays work. null and undefined throw, because for…in cannot walk them.

Return Value

Return ValueDescription
Array of stringsEnumerable own names plus enumerable prototype names. The docs note that order is not guaranteed across JS platforms. The source object is not mutated.

Ramda Examples

📚 Getting Started

The official constructor sample, then the same instance compared with own-only keys.

Example 1 — Official Instance Keys

Own x and enumerable prototype y both appear.

Ramda
const F = function () { this.x = 'X'; };
F.prototype.y = 'Y';
const f = new F();
R.keysIn(f);
//=> ['x', 'y']
Try It Yourself

How It Works

x is assigned on the instance. y is an enumerable field on F.prototype. for…in visits both. That is the docs sample from ramdajs.com.

Example 2 — vs R.keys

keysIn sees the prototype. keys does not.

Ramda
R.keysIn(f);
//=> ['x', 'y']
R.keys(f);
//=> ['x']
Try It Yourself

How It Works

R.keys uses own enumerable names (modern Object.keys). keysIn uses for…in. JSON field lists almost always want keys. Enumerable prototype defaults almost always want keysIn.

📈 Practical Patterns

Object.create defaults, a null throw compared with keys, then a field count in a pipe.

Example 3 — Object.create and Empty Object

Inherited enumerable defaults appear. An empty object does not list toString.

Ramda
const proto = { role: 'dev' };
const child = Object.create(proto);
child.name = 'Ada';
R.keysIn(child);
//=> ['name', 'role']
R.keys(child);
//=> ['name']

R.keysIn({});
//=> []
Try It Yourself

How It Works

role is enumerable on the prototype, so keysIn includes it. Object.prototype.toString is usually non-enumerable, so {} still prints [].

Example 4 — null Throws

keysIn has no nil guard. keys returns [] instead.

Ramda
try {
  R.keysIn(null);
} catch (err) {
  err.name;
}
//=> 'TypeError'

R.keys(null);
//=> []
Try It Yourself

How It Works

for (prop in null) throws. keysIn does not catch that. Mixed JSON lists that may contain holes should use R.keys, or guard with R.isNil first.

Example 5 — Length with pipe

Count enumerable names on the chain. Arrays still list index strings.

Ramda
const countOnChain = R.pipe(R.keysIn, R.length);
countOnChain(f);
//=> 2

R.keysIn(['a', 'b']);
//=> ['0', '1']
Try It Yourself

How It Works

Arity 1 makes keysIn a clean first step in a pipe. Array indexes are enumerable own keys, so a dense array looks the same as R.keys unless something enumerable was added on Array.prototype.

Browser Support

R.keysIn() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.2.0+ · Any JS runtime

Ramda.js R.keysIn()

Load Ramda 0.2.0 or later via CDN or npm, then call R.keysIn with an object. No extra browser API is required.

100% With Ramda 0.2.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.keysIn() Universal

Bottom line: Safe in any project that includes Ramda 0.2.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.keysIn(obj) returns an array of enumerable property names on obj, including names inherited from the prototype. Non-enumerable names such as toString are skipped. Added in v0.2.0.
A constructor assigns this.x and sets F.prototype.y. For an instance f, R.keysIn(f) is ['x', 'y'].
keys lists own enumerable names only. keysIn is a for-in loop, so enumerable prototype names count too. Native for-in is the same walk without a named helper.
R.keysIn(null) and R.keysIn(undefined) throw, because for-in cannot walk null. R.keys(null) returns [] instead.
No. Object.prototype.toString is usually non-enumerable, so R.keysIn({}) is []. Enumerate only names that for-in would visit.
No. R.keysIn is a stable Ramda object helper from v0.2.0. It is not deprecated, experimental, or non-standard.

Continue to R.lens()

Learn how to focus get and set on one part of a structure using Ramda R.lens().

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