1.通过instanceof判断
instanceof运算符用于检验构造函数的prototype属性是否出现在对象的原型链中的任何位置,返回一个布尔值
let a = []
let b = {}
a instanceof Array true
a instanceof Array false
2.通过constructor判断
实例的构造函数属性constructor指向构造函数,通过constructor属性可以判断是否为一个数组
let a = []
a.constructor === Array true
3.通过Object.prototype.toString.call()判断
Object.prototype.toString.call()//可以获取到对象的不同类型
Object.prototype.toSteing.call(a) = ["object array"] true
4.通过Array.isArray()判断
Array.isArray()用于确定传递的值是否是一个数组,返回一个布尔值
5.补充:typeof
typeof 只能检测 基本数据类型,包括boolean、undefined、string、number、symbol,而null ,Array、Object ,使用typeof出来都是Object,函数的typeof 是function 无法检测具体是哪种引用类型