Bug Tracker

Opened 7 years ago

Closed 7 years ago

#9026 closed bug (invalid)

bug in "inArray"

Reported by: anas1305@… Owned by: anas1305@…
Priority: low Milestone: 1.next
Component: core Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:

Description

this function "$.inArray" does not work properly in IE, it returns "undefined" instead of "-1". to correct, you just need to put "Array.indexOf" instead of "array.indexOf" that's all.

Change History (5)

comment:1 Changed 7 years ago by addyosmani

Component: unfiledmisc
Owner: set to anas1305@…
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket!

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

comment:2 Changed 7 years ago by Rick Waldron

There is no occurrence of "array.indexOf" in the entire jQuery code base.

comment:3 in reply to:  2 Changed 7 years ago by anas1305@…

Status: pendingnew

Replying to rwaldron:

There is no occurrence of "array.indexOf" in the entire jQuery code base.

you can find this in lines 677 & 678. And below the code snippet found in jquery version 1.5.2:

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;
},

comment:4 Changed 7 years ago by timmywil

Component: misccore
Status: newpending

Your correction would not fix the problem. As long as array is an Array, and indexOf is supported, it will be used and it returns -1 if elem is not present in the array. I have verified that inArray is working correctly: http://jsfiddle.net/timmywil/62tF9/. So we still need a test case showing where inArray returns undefined.

comment:5 Changed 7 years ago by Rick Waldron

Resolution: invalid
Status: pendingclosed

As you can see, in the _most recent_ version of the source, there is no "array.indexOf":

https://github.com/jquery/jquery/blob/master/src/core.js#L665

Additionally, your recommendation to change this to Array.indexOf is wrong - there is no static "indexOf" method on the Array object.

http://jsfiddle.net/rwaldron/ED6xa/

Version 0, edited 7 years ago by Rick Waldron (next)
Note: See TracTickets for help on using tickets.