js判断是否是数组的四种方法

方法一

// 使用instanceof:
[2,3] instanceof Array === true

方法二

// 使用constructor:
[2,3].constructor === Array

方法三

// 使用prototype:
Object.prototype.toString.call([2,3]) === "[object Array]"

方法四

// 使用es6:
Array.isArray([2,3]) === true
posted @ 2020-09-09 01:54  Marphy  阅读(721)  评论(0编辑  收藏  举报