0

I have a large app that I use for (var i in array) and it worked well, till I see that in IE in Windows 8 It doesn't work because it returns as one of its indexes the property: indexOf I understand now that it was not a good practice to do it, but is there a way that I can still use it in IE (as it works for other browsers). Do they have some kind of backward compatible?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shlomo
  • 357
  • 3
  • 11
  • use a normal `for` loop? – VLAZ Oct 30 '16 at 12:25
  • or the `forEach` array method, e.g. `myArray.forEach(function(value, index) { ... });` – JVDL Oct 30 '16 at 12:30
  • See the answers to the linked question. You *can* use `for-in` with arrays, but it's not what it's for, and if you add an enumerable property to `Array.prototype` (as you apparently are to shim `indexOf`), you have to include `hasOwnProperty` calls (demonstrated in a couple of the answers there). – T.J. Crowder Oct 30 '16 at 12:34
  • As a side note: On most vaguely-current versions of IE, you could make `indexOf` **non-enumerable**. But I think all of the ones where you can do that also have `indexOf` natively, so... – T.J. Crowder Oct 30 '16 at 12:35

0 Answers0