Well, .inArray() , of course, loop over an array if Array.prototype.indexOf() not available:
code snippet
inArray: function( elem, array ) { if ( array.indexOf ) { return array.indexOf( elem ); } for ( var i = 0, length = array.length; i < length; i++ ) { if ( array[ i ] === elem ) { return i; } } return -1; },
code snippet
If you just want to find out if an entry is contained in an array, you can just want .join() and use String.prototype.indexOf() .
This, of course, can no longer return the index. Therefore, you will need to write your own logic. This can be done easily by changing the code above. For instance:
Array.prototype.ourIndexOf = function(v) { for ( var i = 0, length = this.length; i < length; i++ ) { if ( typeof this[i] === 'string' && this[i].indexOf(v) > -1 ) { return i; } } return -1; }; ['Foobar', 'baseball', 'test123'].ourIndexOf('base')
source share