Home  >  Article  >  Web Front-end  >  Finally solved the problem that IE8 does not support the indexOf method of array_javascript skills

Finally solved the problem that IE8 does not support the indexOf method of array_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:38:261087browse

Here’s the solution I found:

Before using the indexOf method, execute the following js. The principle is that if it is found that the array does not have an indexOf method, this method will be added.

Copy code The code is as follows:

if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;

var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from = len;

for (; from < len; from )
{
if (from in this &&
this[from] === elt)
return from;
}
Return -1;
};
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn