Bug Tracker

Opened 5 years ago

Closed 5 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 5 years ago by addyosmani

  • Component changed from unfiled to misc
  • Owner set to anas1305@…
  • Priority changed from undecided to low
  • Status changed from new to pending

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 follow-up: Changed 5 years ago by rwaldron

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

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

  • Status changed from pending to new

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 5 years ago by timmywil

  • Component changed from misc to core
  • Status changed from new to pending

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 5 years ago by rwaldron

  • Resolution set to invalid
  • Status changed from pending to closed

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 5 years ago by rwaldron (next)
Note: See TracTickets for help on using tickets.