我想找到特定的键值是否是嵌套对象。
{
'a': {
'area': 'abc'
},
'b': {
'area': {
'city': 'aaaa',
'state': 'ggggg'
}
}
}
在上面的例子中,我想找到'a'和'b'是对象还是嵌套对象?
我想找到特定的键值是否是嵌套对象。
{
'a': {
'area': 'abc'
},
'b': {
'area': {
'city': 'aaaa',
'state': 'ggggg'
}
}
}
在上面的例子中,我想找到'a'和'b'是对象还是嵌套对象?
如果您想知道对象中的所有键是否都包含嵌套对象,那么一种可能的解决方案是使用R.map
and将对象的所有值转换为布尔值R.propSatisfies
,表示嵌套属性是否为对象。
const fn = R.map(R.propSatisfies(R.is(Object), 'area'))
const example = {
'a': {
'area': 'abc'
},
'b': {
'area': {
'city': 'aaaa',
'state': 'ggggg'
}
}
}
console.log(fn(example))
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
如果您只想知道对象的特定键是否包含嵌套对象,那么您可以使用R.prop
and的组合来做到这一点R.propSatisfies
。
const fn = R.pipe(R.prop, R.propSatisfies(R.is(Object), 'area'))
const example = {
'a': {
'area': 'abc'
},
'b': {
'area': {
'city': 'aaaa',
'state': 'ggggg'
}
}
}
console.log('a:', fn('a', example))
console.log('b:', fn('b', example))
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>