Home >Web Front-end >JS Tutorial >js 解决IE8不支持isArray的方法

js 解决IE8不支持isArray的方法

WBOY
WBOYOriginal
2016-06-01 09:54:291759browse

具体解决方法如下:

假如不存在 Array.isArray(),则在其他代码之前运行下面的代码将创建该方法。

<code class="language-javascript">if (!Array.isArray) {
  Array.isArray = function(arg) {
    return Object.prototype.toString.call(arg) === '[object Array]';
  };
}</code>

解释:

代码首先判断是否存在Array.isArray,如果不存在,则将自定义的JS函数赋值给Array.isArray。

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