Skip to main content

Bug Tracker

Side navigation

#9026 closed bug (invalid)

Opened April 30, 2011 09:10AM UTC

Closed April 30, 2011 05:38PM UTC

bug in "inArray"

Reported by: anas1305@gmail.com Owned by: anas1305@gmail.com
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.

Attachments (0)
Change History (5)

Changed April 30, 2011 12:52PM UTC by addyosmani comment:1

component: unfiledmisc
owner: → anas1305@gmail.com
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.

Changed April 30, 2011 02:06PM UTC by rwaldron comment:2

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

Changed April 30, 2011 04:54PM UTC by anas1305@gmail.com comment:3

status: pendingnew

Replying to [comment:2 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;
},

Changed April 30, 2011 05:03PM UTC by timmywil comment:4

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.

Changed April 30, 2011 05:38PM UTC by rwaldron comment:5

_comment0: 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 '''A'''rray.indexOf is wrong - there is no static "indexOf" method on the Array object. \ \ http://jsfiddle.net/rwaldron/ED6xa/ \ \ 1304185166087764
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-677

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/