Ramda.js R.keys() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.keys() answers a name question: which own enumerable fields does this object have? You pass an object. You get an array of strings. Values do not appear. Prototype methods do not appear. A key whose value is undefined still appears.

The official sample is the whole idea. R.keys({a: 1, b: 2, c: 3}) is ['a', 'b', 'c']. Native JavaScript is Object.keys. That throws on null. keys returns [] instead. Need inherited names too? That is the next helper, R.keysIn. Need the values? That is R.values. Lodash _.keys is data-first; Ramda is R.keys(obj) and curried.

Syntax

Call R.keys. Start with this line.

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

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

Library declarations
Ramda
R.keys(obj)

Parameters

ParameterDescription
objRequired. Object. The record to inspect. Arrays work: indexes become the names. null, undefined, and other primitives yield [].

Return Value

Return ValueDescription
Array of stringsOwn enumerable property names. The docs note that order is not guaranteed across JS platforms. The source object is not mutated.

Ramda Examples

📚 Getting Started

The official name list, then the same idea compared with keysIn on a prototype.

Example 1 — Official Object Keys

Own enumerable names come back as an array of strings.

Ramda
R.keys({ a: 1, b: 2, c: 3 });
//=> ['a', 'b', 'c']
Try It Yourself

How It Works

Only the names are listed. The numbers stay on the object. That is the docs sample from ramdajs.com. The docs also note that order is not guaranteed across every JS platform.

Example 2 — vs R.keysIn

keys lists own names. keysIn also includes enumerable names on the prototype.

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

How It Works

x is assigned on the instance. y lives on F.prototype and is enumerable, so keysIn sees it. Next Object helper is keysIn. JSON field lists almost always want keys, not keysIn.

📈 Practical Patterns

Array indexes, a null-safe empty list, undefined values, then a field count in a pipe.

Example 3 — Arrays, Empty Object, and null

Array indexes are own keys. An empty object is []. null is [] instead of a throw.

Ramda
R.keys(['a', 'b']);
//=> ['0', '1']
R.keys({});
//=> []
R.keys(null);
//=> []
Try It Yourself

How It Works

Arrays are objects whose own keys are index strings. Native Object.keys(null) throws. keys returns [] because a primitive or nil value fails Object(obj) === obj.

Example 4 — Undefined Values

A key set to undefined still appears. An empty object has no own keys, even though it inherits toString.

Ramda
R.keys({ n: undefined, ok: 1 });
//=> ['n', 'ok']
R.keys({});
//=> []
Try It Yourself

How It Works

Existence is not truthiness. n is an own key. toString on {} is inherited and usually non-enumerable, so it does not appear in keys.

Example 5 — Length with pipe

Count own fields, or map keys over a list of objects.

Ramda
const countOwn = R.pipe(R.keys, R.length);
countOwn({ a: 1, b: 2, c: 3 });
//=> 3

R.map(R.keys, [{ a: 1 }, { b: 2, c: 3 }]);
//=> [['a'], ['b', 'c']]
Try It Yourself

How It Works

Arity 1 makes keys a clean first step in a pipe and a fine mapper. R.invertObj walks this same list internally when it flips an object.

Browser Support

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

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.keys()

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

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

Bottom line: Safe in any project that includes Ramda 0.1.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.keys(obj) returns an array of the object's own enumerable property names. Inherited prototype names do not appear. Added in v0.1.0.
R.keys({a:1, b:2, c:3}) is ['a', 'b', 'c'].
keys is own enumerable names only. keysIn also includes enumerable prototype names. Native Object.keys throws on null; R.keys(null) returns [].
The docs say order is not guaranteed across JS platforms. Modern engines usually follow insertion order for string keys, but you should not depend on a sort.
Yes. Own keys count even when the value is undefined. Existence is not truthiness.
No. R.keys is a stable Ramda object helper from v0.1.0. It is not deprecated, experimental, or non-standard.

Continue to R.keysIn()

Learn how to list own and enumerable prototype property names using Ramda R.keysIn().

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