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?

0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

jQuery.inArray is my saviour. Thanks for the heads up.
+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.
20

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

if ($.inArray(dealWith, buyArray) != -1) {

5 Comments

You should add the jQuery tag to your question IMO.
So he gave you the answer then you decided to post it and accept your own as the answer?
@Blackunknown 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.
TBF, you should have given the answer to ZER0
To fold to popular opinion. I have updated the accepted answer to @ZER0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.