Ramda’s R.valuesIn() answers a chain question: which enumerable values exist on this object or anywhere up its prototype? You pass an object. You get an array of values. Own enumerable data counts. Inherited enumerable data counts. Non-enumerable fields such as toString do not.
The official sample is the whole idea. A constructor writes this.x = 'X'. y is assigned on the prototype as 'Y'. R.valuesIn(f) is ['X', 'Y']. Native JavaScript is a for…in loop that reads obj[prop]. That throws on null. valuesIn does the same, because the source is that loop. Need own data only, and a quiet [] on null? That is the previous helper, R.values. Need the names on the chain? That is R.keysIn. Need both as pairs? That is R.toPairsIn. Next Object helper is R.view.
Syntax
Call R.valuesIn. Start with this line.
Ramda
R.valuesIn(obj)
Call
What it does
R.valuesIn(obj)
Primary signature.
R.valuesIn(...)
Call the object helper.
Prefer import { valuesIn } from "ramda" when you want a named import.
Library declarations
Ramda
R.valuesIn(obj)
Parameters
Parameter
Description
obj
Required. Object. The record to inspect. Arrays work: items come back as the list. null and undefined throw, because for…in cannot walk them.
Return Value
Return Value
Description
Array of values
Enumerable own values plus enumerable prototype values. 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 values.
Example 1 — Official Instance Values
Own X and enumerable prototype Y both appear.
Ramda
const F = function () { this.x = 'X'; };
F.prototype.y = 'Y';
const f = new F();
R.valuesIn(f);
//=> ['X', 'Y']
x is assigned on the instance as 'X'. y is an enumerable field on F.prototype as 'Y'. for…in visits both and valuesIn pushes the data. That is the docs sample from ramdajs.com.
Example 2 — vs R.values and R.keysIn
valuesIn sees prototype data. values does not. keysIn lists the names instead.
Ramda
const F = function () { this.x = 'X'; };
F.prototype.y = 'Y';
const f = new F();
R.valuesIn(f);
//=> ['X', 'Y']
R.values(f);
//=> ['X']
R.keysIn(f);
//=> ['x', 'y']
R.values walks own enumerable names (via keys). valuesIn uses for…in and pushes obj[prop]. JSON field lists almost always want values. Enumerable prototype defaults almost always want valuesIn. Need the names? That is R.keysIn.
📈 Practical Patterns
Object.create defaults, a null throw compared with values, then a join in a pipe.
Example 3 — Object.create and Empty Object
Inherited enumerable defaults appear. An empty object does not list toString.
Arity 1 makes valuesIn a clean first step in a pipe. Array indexes are enumerable own keys, so a dense array looks the same as R.values unless something enumerable was added on Array.prototype.
Compatibility
Browser Support
R.valuesIn() 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.valuesIn()
Load Ramda 0.2.0 or later via CDN or npm, then call R.valuesIn 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.valuesIn()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.valuesIn(obj) returns an array of enumerable property values on obj, including values inherited from the prototype. Non-enumerable fields such as toString are skipped. Added in v0.2.0.
A constructor assigns this.x = 'X' and sets F.prototype.y = 'Y'. For an instance f, R.valuesIn(f) is ['X', 'Y'].
values lists own enumerable data only. valuesIn is a for-in loop that pushes obj[prop], so enumerable prototype values count too. keysIn lists the names from that same walk.
R.valuesIn(null) and R.valuesIn(undefined) throw, because for-in cannot walk null. R.values(null) returns [] instead.
No. Object.prototype.toString is usually non-enumerable, so R.valuesIn({}) is []. Only values that for-in would visit appear.
No. R.valuesIn is a stable Ramda object helper from v0.2.0. It is not deprecated, experimental, or non-standard.