I need to search for the presence of an array inside an array. It is similar to jQuery.inArray function.
For
var a = [ [1,2], [1,3] ];
console.log( jQuery.inArray([1,3],a ) )
I get -1 as ans. How to do this?
Thank you
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.
In V8 (that is, Chrome), there is a nifty trick: while
==does not work for arrays,<= && >=does.You can iterate and check for each item if it’s appearent:
For other browsers, you’d need a function that checks for array equality:
http://www.svendtofte.com/code/usefull_prototypes/prototypes.js
Then: