Reputation: 2040
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
Upvotes: 1
Views: 5072
Reputation: 19070
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);
Upvotes: 1
Reputation: 7403
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
Upvotes: 1