I want to check if "foo" exists in the array named "Array", but $.inArray always returns -1. Why does it return -1 and how do I solve this?
Here is my code in a jsFiddle:
var Array = []
Array.push({'test':'fuu','url':'sdfsdfsdf'});
Array.push({'test':'qsgbfdsbgsdfbgsfdgb','url':'sdfssffbgsfdbgdfsdf'});
if($.inArray('fuu',Array) != -1) alert('present');
else alert('absent');
alert($.inArray('fuu',Array));
'fuu'is not actually in the array, it’s a value of an object inside of the array. I’m afraid that you need a more complex check. I would also not useArrayas the variable name as that’s the name of theArrayobject, but apparently it’s not a reserved word? not sure.