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

js 解决IE8不支持isArray的方法

WBOY
Release: 2016-06-01 09:54:29
Original
1763 people have browsed it

具体解决方法如下:

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

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

解释:

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template