我有这个对象:
let obj = {
matrimonyUrl: 'christian-grooms',
search_criteria:
'a:2:{s:6:"gender";s:4:"Male";s:9:"community";s:9:"Christian";}',
mothertongue: null,
religion: 'Christian',
caste: '',
country: null
};
我需要删除该对象中的所有键/值对,其中值是空白的,即 ''
因此caste: ''
,在上述情况下应删除该属性。
我试过了:
R.omit(R.mapObjIndexed((val, key, obj) => val === ''))(obj);
但这没有任何作用。reject
也不起作用。我究竟做错了什么?
您可以使用R.reject(或R.filter)通过回调从对象中删除属性:
const obj = {
matrimonyUrl: 'christian-grooms',
search_criteria:
'a:2:{s:6:"gender";s:4:"Male";s:9:"community";s:9:"Christian";}',
mothertongue: null,
religion: 'Christian',
caste: '',
country: null
};
const result = R.reject(R.equals(''))(obj);
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js"></script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句