31

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/

3 Answers 3

59

Try this. it's simple

_.has(dependsOn, field)

it returns true if the RHID key exist in dependsOn. in above case it returns false

Sign up to request clarification or add additional context in comments.

Comments

12

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/

7 Comments

something is wrong. Narendra CM can you help me with this jsfiddle.net/88gwp87k
Whats the problem?? LeonelMatiasDomingos
always return false and seems that must return true jsfiddle.net/88gwp87k/2
Did you check my earlier fiddle jsfiddle.net/88gwp87k/1. This returns true
i've solved other way... can you please help me with returning the object with db=='NOME' in jsfiddle.net/4w2z418c/1
|
1
_.chain(dependsOn).findKey(field).isString().value();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.