admin管理员组文章数量:1429768
i am trying to return true if object exists with
var primary={
"RHID": {
"type": "numeric"
},
"CD_DOC_ID": {
"type": "numeric"
},
"SEQ": {
"type": "numeric"
}
}
console.log(_.contains(primary, 'RHID'))
But aways get false. Thanks
i am trying to return true if object exists with
var primary={
"RHID": {
"type": "numeric"
},
"CD_DOC_ID": {
"type": "numeric"
},
"SEQ": {
"type": "numeric"
}
}
console.log(_.contains(primary, 'RHID'))
But aways get false. Thanks
Share Improve this question edited Jan 27, 2016 at 13:04 suvroc 3,0621 gold badge17 silver badges29 bronze badges asked Jan 27, 2016 at 12:27 Leonel Matias DomingosLeonel Matias Domingos 2,0806 gold badges36 silver badges54 bronze badges3 Answers
Reset to default 3You can use _.has
method
console.log(_.has(primary, 'RHID'))
RHID
is a key inside the object primary
, so you should look up in the keys of primary
.
loDash function _.keys
returns an array of all the object keys, yo ucan use it this way:
console.log(_.contains(_.keys(primary), 'RHID')) // true
A lodash
solution using has() or hasIn():
var primary=
{
"RHID": {
"type": "numeric"
},
"CD_DOC_ID": {
"type": "numeric"
},
"SEQ": {
"type": "numeric"
}
}
console.log(_.has(primary, 'RHID'));
_.has()
checks for own properties, _.hasIn()
verifies for own and inherited ones.
But it would be better to use in
operator:
var primary=
{
"RHID": {
"type": "numeric"
},
"CD_DOC_ID": {
"type": "numeric"
},
"SEQ": {
"type": "numeric"
}
}
console.log('RHID' in primary);
本文标签: javascriptlodash find object inside objectStack Overflow
版权声明:本文标题:javascript - lodash find object inside object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745481134a2660176.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论