I tried to set an inArray with an object but it don’t works
var test = {aa:1, bb:0}
console.log($.inArray(1,test))
I always have -1
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$.inArrayis designed to work with arrays. It will not work properly with objects as you have already figured out (it returns -1 no matter the circumstance). Speaking of objects, the syntax you used to create an object literal is ill-formed, it’s not written as{ a = b }but rather as{ a : b }. Here is an example:I also see that you’re trying to find if a property of an object has a certain value, and not that the object has the property at all. If it were the latter case we’d use the
inkeyword or.hasOwnPropertyfunction. But we’ll need to make our own function for your case. Try this:And we’ll use it like this: