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)
Call
What 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
Parameter
Description
obj
Required. Object. The record to inspect. Arrays work. null and undefined throw, because for…in cannot walk them.
Return Value
Return Value
Description
Array of strings
Enumerable 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']
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.
Compatibility
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 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.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.