- 使用
instanceof// 如果返回true那么说明就是数组 if (value instanceof Array){ } - 使用
Object.prototype.toString// 由于数组重写了toString方法,我们可以使用Object.prototype.toString方法来判断对象是不是数组 if (Object.prototype.toString.call(value) === "[object Array]"){ } - 使用
value.constructor.name// 检测构造函数的名称是不是Array if (value.constructor.name === "Array"){ } - 使用ES5的
Array.isArray()// ES5标准 简单 好用 低版本浏览器不支持 if (Array.isArray(value)){ }
如何判断一个对象是不是数组
2020-10-19 14:37:44
浏览数 (4)


