Created
July 13, 2013 07:23
-
-
Save E01T/5989790 to your computer and use it in GitHub Desktop.
How to fix Array indexOf() in JavaScript for IE browsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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