Reputation: 2040
I need help with lodash cause i dont understand functional programming and lodash is very helpfull with object/arrays operations.
I need to search objects inside object and return true if key exists. I've setup a jsfiddle. Apreciate your help.
var dependsOn={
"Cadastro": {
"RHID": "RHID"
},
"Agregados":{
"CD_DOC":"CD_DOC"
}
"Documentos":{
"RHID":"CD_DOC"
}
}
var field='RHID'
alert(_.contains(_.keys(dependsOn), field))
https://jsfiddle.net/88gwp87k/
Upvotes: 31
Views: 72294
Reputation: 880
Try this. it's simple
_.has(dependsOn, field)
it returns true if the RHID
key exist in dependsOn. in above case it returns false
Upvotes: 56
Reputation: 1426
try this
var dependsOn={
"Cadastro": {
"RHID": "RHID"
},
"Agregados":{
"CD_DOC":"CD_DOC"
},
"Documentos":{
"RHID":"CD_DOC"
}
}
var field='RHID'
alert(_.some(dependsOn, function(o) { return _.has(o, field); }));
Updated your fiddle: https://jsfiddle.net/88gwp87k/1/
Upvotes: 12