Use array.indexOf if available (speeds up modern browsers). Thanks to lrbabe and Andrea for the patch. Fixes #5160.

This commit is contained in:
lrbabe 2009-11-11 15:15:58 -05:00 committed by John Resig
parent 5ac2e0837c
commit c07d15d5a2

View file

@ -441,6 +441,10 @@ jQuery.extend({
}, },
inArray: function( elem, array ) { inArray: function( elem, array ) {
if ( array.indexOf ) {
return array.indexOf( elem );
}
for ( var i = 0, length = array.length; i < length; i++ ) { for ( var i = 0, length = array.length; i < length; i++ ) {
if ( array[ i ] === elem ) { if ( array[ i ] === elem ) {
return i; return i;