Skip to main content

Bug Tracker

Side navigation

#10700 closed bug (invalid)

Opened November 07, 2011 11:55AM UTC

Closed November 07, 2011 01:33PM UTC

Last modified December 16, 2013 09:17PM UTC

IE8 error at jQuery.inArray()

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7
Keywords: Cc:
Blocked by: Blocking:
Description

I've downloaded latest jQuery 1.7 minified version. Updated my application and found that on IE8 jQuery.inArray() returns error.

My test was:

jQuery.inArray("t", "test");

jQuery.inArray("e", "test");

It works for:

jQuery.inArray("e", ["t", "e"]);

I didn't tested on IE lower then 8. On FireFox/Chrome/Opera latest versions and on IE9 it works.

Attachments (0)
Change History (10)

Changed November 07, 2011 01:33PM UTC by rwaldron comment:1

resolution: → invalid
status: newclosed

Why would you expect inArray to work on a string?

Changed November 07, 2011 02:07PM UTC by darkyndy comment:2

Until version 1.7 it worked on all browsers (tested with version 1.6.4 last time).

Changed November 07, 2011 02:24PM UTC by rwaldron comment:3

jQuery.inArray() has always been documented as accepting the following arguments: value and array ( with 1.7, we implemented support for the fromIndex argument). Never has this function claimed to accept string a argument; that it did is purely a coincidence and likely should've been avoided.

Changed November 07, 2011 02:24PM UTC by rwaldron comment:4

Changed November 07, 2011 04:02PM UTC by darkyndy comment:5

Yes, I know that second parameter is array, but as the description of the inArray says "The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match." and indexOf supports both array and strings.

Now the issue is that until 1.7 inArray worked as indexOf (supporting both array and strings) on every browser that I worked with.

My suggestion if this function will be left in this way at least add in documentation that it will work only on arrays and also this will break the functionality that is used until now on IE8 (and I suppose on IE<8 because there isn't any indexOf native method).

Changed November 07, 2011 04:42PM UTC by dmethvin comment:6

I think we're good where we are, especially since the name implies, nay specifies, that it expects an array.

Changed November 07, 2011 07:34PM UTC by ajpiano comment:7

I agree with dmethvin, I doubt there are too many people who are using $.inArray instead of String.prototype.indexOf, and those people should fix their code instead of us documenting that something that was never supported is in fact, not supported.

Perhaps the docs could be slightly tweaked to say that "The $.inArray() method is similar to JavaScript's native Array.prototype.indexOf method in that it returns -1 when it doesn't find a match." and indexOf supports both array and strings so that it's clear that it's not just magically "similar" - and thus interchangeable with - String.prototype.indexOf

Changed November 07, 2011 07:46PM UTC by rwaldron comment:8

The only reason jQuery.inArray() even exists is because IE6, 7 & 8 don't support Array.prototype.indexOf. Support for String.prototype.indexOf has existed since ES1 and supported in IEs since the mid-90s. This is further evidence that jQuery.inArray() was never expected to work with strings.

Changed December 16, 2013 08:31PM UTC by anonymous comment:9

Never heard such pompous statements from developers.

The whole point of using inArray is because indexOf doesn't work in IE 7 & 8. By disabling its usage from string, you are in essence making it difficult for any js developer to have anything similar to indexOf for older browser support.

Changed December 16, 2013 09:17PM UTC by rwaldron comment:10

Replying to [comment:9 anonymous]:

Never heard such pompous statements from developers. The whole point of using inArray is because indexOf doesn't work in IE 7 & 8. By disabling its usage from string, you are in essence making it difficult for any js developer to have anything similar to indexOf for older browser support.

That's rude and worse: I don't think you actually read the responses. No one is blocked from using indexOf on strings in any browser—it's available _natively_. Array.prototype.indexOf is not implemented in IE6, 7 & 8, but String.prototype.indexOf is.