Javascript Indexof Vs Array.prototype.indexof Ie Compatibility Error
Possible Duplicate: Why doesn't indexOf work on an array IE8? I recently developed a script that uses native Javascript and jQuery. Most of my development has been with IE 9, Ch
Solution 1:
This question has come up many times, another Stackoverflow thread can be found here: How to fix Array indexOf() in JavaScript for Internet Explorer browsers
Several people on different threads have recommended using this code from MDC. This appears to be the code:
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
varfrom = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++)
{
if (frominthis &&
this[from] === elt)
returnfrom;
}
return -1;
};
}
Just run this code before making any calls indexOf()
Post a Comment for "Javascript Indexof Vs Array.prototype.indexof Ie Compatibility Error"