Bug Tracker

Ticket #9026 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

bug in "inArray"

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

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

comment:1 Changed 4 years ago by addyosmani

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

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: ↓ 3 Changed 4 years ago by rwaldron

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

comment:3 in reply to: ↑ 2 Changed 4 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 4 years ago by timmywil

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

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

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

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