check if value exists in json array
jquery, json
Solution
Your array contains JSON objects. So you need to look inside of each object to see if its field has the desired value (or at least, that's what I gather you're trying to do judging by your code).
So perhaps something along the lines of:
$(returnedData).each(function() {
if (this.pathway_action_fk == 1) {
$('#script').addClass('active');
}
});
Example: http://jsfiddle.net/qvsbT/
Problem
I want to check via js/jquery if a value exits in a json array: ``` [{"pathway_action_fk":"1"},{"pathway_action_fk":"2"},{"pathway_action_fk":"4"}] ``` I have tried without success: ``` $.ajax({ type: "POST", url: "scripts/get_actions_allowed.php", data: 'pathway=' + pathway_pk, dataType: "json", success: function(returnedData) { if ($.inArray('1', returnedData)){ $('#script').addClass('active'); }... ``` If I put in after success: ``` alert(returnedData); ``` I get`[object Object],[object Object]` which is the correct number of objects that should be returned. Removing json as dataType shows the correct values...