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);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745481134a4629560.html
评论列表(0条)