js里面判断数组的方式

1 Array.isArray

let arr = [1, 2, 3]
 console.log(Array.isArray(arr));    // true

2 instanceof

  let arr = [1, 2, 3]
  console.log(arr instanceof Array);    // true

3 constructor

 let arr = [1, 2, 3]
  console.log(arr.constructor === Array);    // true

4 利用原型对象

   let arr = [1, 2, 3]
        console.log(Array.prototype.isPrototypeOf(arr));

你可能感兴趣的:(js)