I am trying to check if a value is present in the below nested object:
var Obj = {
"testname":"Validator",
"dataTableName":"y",
"dataColumnName":"y",
"CheckFilter":"CheckBoxFilter",
"CheckFilterSettings":{
"values":[
"70.00"
],
"hierarchyPaths":[
]
}
}
I tried using
for (var i in Obj) {
if (Obj[i].CheckFilterSettings.values[0] === "70.00"){
console.log("Value Found");
}else{
console.log("Value Not Found");
}
}
Could someone please suggest where I am going wrong.
You can use
Object.keys()
like this:If you want to check that the
values
array is not empty, and that the path to that array remains constant, you could just use:Note that this assumes an array of objects, which is not evident from the provided data structure. If that’s the entire object, then try:
Your Obj[i] is itself the key, so, do not call "CheckFilterSettings" on Obj[i] again.
Check this one-
no need to loop through the object. just simply use es20 feature optional chaining:
It can be simplified, try this…