如何判断是否为数组

以下方法返回值均为布尔值
let arr = []
arr.constructor === Array //这个方式不是很稳妥 容易被欺骗
Array.prototype.isPrototypeOf(arr)
arr instanceof Array
Object.getPrototypeOf(arr) === Array.prototype
Array.isArray(arr)//内部实现为下面方法
Object.prototype.toString.call(arr) === '[object Array]'

  

原文地址:https://www.cnblogs.com/zhenjianyu/p/12964854.html