Skip to content

Instantly share code, notes, and snippets.

@E01T
Created July 13, 2013 07:23
Show Gist options
  • Save E01T/5989790 to your computer and use it in GitHub Desktop.
Save E01T/5989790 to your computer and use it in GitHub Desktop.
How to fix Array indexOf() in JavaScript for IE browsers
/*
If you have worked with JavaScript at any length you are aware that IE does not implement
the ECMAScript function for Array.prototype.indexOf() [including IE8]. Not a huge problem
because you can extend the functionality on your page with the following code.
*/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment