Say I have:
a=[[1,2],[3,4],[5,6]]
Is this wrong?
a.indexOf([1,2])
Why -1?
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.
Because
[1,2] == [1,2]isfalseThere is no equality of different instances of javascript objects.
From the MDN on
==:You could build your own function to look for an array in an array, but in this case, as you would have to check all elements of the internal arrays (or build a hash code), this won’t be fast. You’d better avoid this kind of search.