Bug Tracker

Modify

Ticket #10700 (closed bug: invalid)

Opened 2 years ago

Last modified 4 months ago

IE8 error at jQuery.inArray()

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

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.

Change History

comment:1 Changed 2 years ago by rwaldron

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

Why would you expect inArray to work on a string?

comment:2 Changed 2 years ago by darkyndy

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

comment:3 Changed 2 years ago by rwaldron

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.

comment:5 Changed 2 years ago by darkyndy

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).

comment:6 Changed 2 years ago by dmethvin

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

comment:7 Changed 2 years ago by ajpiano

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

comment:8 Changed 2 years ago by rwaldron

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.

comment:9 follow-up: ↓ 10 Changed 4 months ago by 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.

comment:10 in reply to: ↑ 9 Changed 4 months ago by rwaldron

Replying to 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.