Search code examples
javascriptarraysobjectlodash

Lodash , check if object exists and property exists and is true


Good morning . I need help on checking if object exists and certain propertie have value of true. Ex:

validations={
  "DSP_INDICADOR": {
    "required": true
  },
  "EMPRESA": {
    "required": true
  },
.....
  "NOME_AVAL": {
    "required": false,
    "notEqualToField": "NOME"
  }
}

and then check for required:true

Thanks in advance


Solution

  • I guess this would be it.

    if (validations["EMPRESA"] && validations["EMPRESA"].required) {
      console.log(true)
    } else {
      console.log(false)
    }