Let's say we have the following js array
var ar = [ [2,6,89,45], [3,566,23,79], [434,677,9,23] ]; var val = [3,566,23,79];
Is there a js builtin function or jQuery one with which you can search the array ar for val?
Thanks
***UPDATE*************
Taking fusion's response I created this prototype
Array.prototype.containsArray = function(val) { var hash = {}; for(var i=0; i<this.length; i++) { hash[this[i]] = i; } return hash.hasOwnProperty(val); }
Use forEach() to find an element in an array The Array. prototype. forEach() method executes the same code for each element of an array. The code is simply a search of the index Rudolf (🦌) is in using indexOf.
Access Array Elements You can access an array element by referring to its index number. The indexes in NumPy arrays start with 0, meaning that the first element has index 0, and the second has index 1 etc.
you could create a hash.
var ar = [ [2,6,89,45], [3,566,23,79], [434,677,9,23] ]; var hash = {}; for(var i = 0 ; i < ar.length; i += 1) { hash[ar[i]] = i; } var val = [434,677,9,23]; if(hash.hasOwnProperty(val)) { document.write(hash[val]); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With