http://ramdajs.com/0.21.0/docs/#prop
Ramda Repl
var myObject = {a: 1, b: 2, c: 3, d: 4};
var newObject = R.filter(R.props('a'), myObject);
//var newObject = R.filter(R.equals(R.props('a')), myObject);
console.log('newObject', newObject);
Right now the code above is returning the entire object:
newObject
{"a":1,"b":2,"c":3,"d":4}
What I would like to do is just return a new object with just the 'a'
key. Or a new object with the a
and b
keys.
const getOnlyGoods = R.pickBy((_, key) => key.includes('good'));
const onlyGoods = getOnlyGoods({
"very good": 90,
"good": 80,
"good enough": 60,
"average": 50,
"bad": 30,
"😡": 10,
});
console.log(onlyGoods);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Use pick:
let newObj = R.pick(['a'], oldObj);
If your filtering criteria is more complex than just existence, you can use pickBy to select via arbitrary predicate functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With