判断是否为数组的方法

66 阅读1分钟

var arr = [1,2,3];

第一种:arr.proto==Array.prototype

第二种:Object.getPrototypeOf(arr)== Array.prototype

第三种:Array. prototype.isPrototypeOf(arr)

第四种:arr.constructor==Array

第五种:arr  instanceof  Array

注:instanceof 运算符用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链上。

第六种:Object. prototype.toString.call(arr)===”[object  Array]”

第七种:ES5新增:Array.isArray(arr)