判断数组方式

1.Object.prototype.tostring.call()

//返回一个表示对象类型的字符串([object Array])
console.log(Object.prototype.toString.call(a));

 

2.原型链

function isArrayUsingPrototype(obj) {
      // 参数一 函数上下文
      // 参数二 要检查的对象
      return Object.prototype.isPrototypeOf.call(Array.prototype, obj);
 }
    console.log(isArrayUsingPrototype(a));

 3.es6中Array.isArray()判断

// 返回true和false
    console.log(Array.isArray(a));

 4.instanceof判断

console.log(a instanceof Array);

5.Array.prototype.isprototypeof()

    // 返回true和false
    console.log(Array.prototype.isPrototypeOf(a));

 

 

阅读剩余
THE END