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)
Call
What 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
Parameter
Description
obj
Required. Object. The record to inspect. Arrays work: indexes become the names. null, undefined, and other primitives yield [].
Return Value
Return Value
Description
Array of strings
Own 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.
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']
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.
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.
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.
Compatibility
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 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.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.