Take the 2-minute tour ×

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
jQuery.inArray is my saviour. Thanks for the heads up. –  Fraser Jun 6 '12 at 22:58
+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. –  Spudley Jun 6 '12 at 22:59
up vote 18 down vote accepted

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

if ($.inArray(dealWith, buyArray) != -1) {
share|improve this answer
You should add the jQuery tag to your question IMO. –  Derek 朕會功夫 Jun 6 '12 at 23:04
So he gave you the answer then you decided to post it and accept your own as the answer? –  Blackunknown Mar 24 at 10:08
@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. –  Fraser Mar 24 at 13:24

Your Answer


