Created
January 21, 2014 18:20
-
-
Save edgar/8545282 to your computer and use it in GitHub Desktop.
In IE8 arrays don't have the method indexOf defined. Implementation taken from MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf Other source could be: http://ecma262-5.com/ELS5_HTML.htm#Section_15.4.4.14
This file contains hidden or 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 (!Array.prototype.indexOf) { | |
Array.prototype.indexOf = function (searchElement, fromIndex) { | |
if ( this === undefined || this === null ) { | |
throw new TypeError( '"this" is null or not defined' ); | |
} | |
var length = this.length >>> 0; // Hack to convert object.length to a UInt32 | |
fromIndex = +fromIndex || 0; | |
if (Math.abs(fromIndex) === Infinity) { | |
fromIndex = 0; | |
} | |
if (fromIndex < 0) { | |
fromIndex += length; | |
if (fromIndex < 0) { | |
fromIndex = 0; | |
} | |
} | |
for (;fromIndex < length; fromIndex++) { | |
if (this[fromIndex] === searchElement) { | |
return fromIndex; | |
} | |
} | |
return -1; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment