IE: indexOf results in "object doesn't support this property or method"
Asked Answered
C

2

26

I have the following if statement:

if (buyArray.indexOf(dealWith,0) != -1){

Which is breaking in ie (ie 8 on XP) with "object doesn't support this property or method".

Anyone have a work around for this?

Conger answered 6/6, 2012 at 22:52 Comment(0)
U
52

yeah, IE<9 doesn't support indexOf. You can implement a shim like the one showed here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf

Or if you already using jQuery you can use inArray. Also underscore has an implementation for it.

Undervalue answered 6/6, 2012 at 22:55 Comment(2)
jQuery.inArray is my saviour. Thanks for the heads up.Conger
+1 for the right answer, plus providing work-arounds. The lesson here is to know that old IE versions have a lot of missing functionality, and to be prepared to work around them.Matthews
C
20

Simply changed to the use jQuery.inArray. Thanks to ZER0 for the heads up

if ($.inArray(dealWith, buyArray) != -1) {
Conger answered 6/6, 2012 at 22:59 Comment(5)
You should add the jQuery tag to your question IMO.Achromic
So he gave you the answer then you decided to post it and accept your own as the answer?Haemato
@Haemato He pointed me to where I could find the solution and I answered with the actual solution which he helped me to find. So if you are going to be pedantic about it, the answer to your question is yes.Conger
TBF, you should have given the answer to ZER0Kitty
To fold to popular opinion. I have updated the accepted answer to @UndervalueConger

© 2022 - 2024 — McMap. All rights reserved.