I want to check if "T1000" exists as an approval "key" in the following JSON. If it exists, then I want to display the corresponding approval "value".
{"approvals":
[
{"approval":
{
"id":"0121920",
"key":"T100",
"value":"Ben Tsu"
}
},
{"approval":
{
"id":"",
"key":"T1000",
"value":"Amy Dong"
}
}
]
}
I'm getting JSON as an Ajax response. I'm trying to loop through all properties and match it to the value passed in as the parameter.
Here's my code but it only spits out object Object, object Object. So, if I have 5 properties, this code spits out object Object 5 times.
I'm passing inputFieldDefaultValue as a parameter to the plugin with the value being T1000. Hence, o.inputFieldDefaultValue.
$.each(response.approvals, function(index, approvals){
if(approvals.approval.key == o.inputFieldDefaultValue){
approvals.approval.value;
}
});
If I do
$.each(response.approvals, function(index, approvals){
if(approvals.approval.key == o.inputFieldDefaultValue){
alert(approvals.approval.value);
}
});
it alerts the corresponding value (Amy Dong) but it still writes object Object (as many times as the properties in the JSON response).