diff options
author | timmywil <tim.willison@thisismedium.com> | 2011-05-28 12:00:28 -0400 |
---|---|---|
committer | timmywil <timmywillisn@gmail.com> | 2011-09-19 15:42:30 -0400 |
commit | 2e0c9bfd364d990051fc3de94d7abd4194b6ce7d (patch) | |
tree | 52bf4cfa6a5171c63056ddb15df741ca3b71747e /src/core.js | |
parent | 25205d3f90f1bda06e7ca95c2aa8c43e535badb4 (diff) | |
download | jquery-2e0c9bfd364d990051fc3de94d7abd4194b6ce7d.tar.gz jquery-2e0c9bfd364d990051fc3de94d7abd4194b6ce7d.zip |
Allow second argument to be passed to array.indexOf. Fixes #9453.
Diffstat (limited to 'src/core.js')
-rw-r--r-- | src/core.js | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/core.js b/src/core.js index 8d9a94f63..8bc3137dd 100644 --- a/src/core.js +++ b/src/core.js @@ -682,18 +682,21 @@ jQuery.extend({ return ret; }, - inArray: function( elem, array ) { - if ( !array ) { - return -1; - } + inArray: function( elem, array, i ) { + var len; - if ( indexOf ) { - return indexOf.call( array, elem ); - } + if ( array ) { + if ( indexOf ) { + return indexOf.call( array, elem, i ); + } - for ( var i = 0, length = array.length; i < length; i++ ) { - if ( array[ i ] === elem ) { - return i; + len = array.length; + i = i && i < 0 ? Math.max( 0, len + i ) : 0; + + for ( ; i < len; i++ ) { + if ( array[ i ] === elem ) { + return i; + } } } |