1. instanceof 操作符判断

用法:arr instanceof Array
instanceof 主要是用来判断某个实例是否属于某个对象

let arr = [];
console.log(arr instanceof Array); // true

2.对象构造函数的 constructor 判断

用法:arr.constructor === Array
Object的每个实例都有构造函数 constructor,用于保存着用于创建当前对象的函数

let arr = [];
console.log(arr.constructor === Array); // true

3.Array 原型链上的 isPrototypeOf

用法:Array.prototype.isPrototypeOf(arr)
Array.prototype 属性表示 Array 构造函数的原型
其中有一个方法是 isPrototypeOf() 用于测试一个对象是否存在于另一个对象的原型链上。

let arr = [];
console.log(Array.prototype.isPrototypeOf(arr)); // true

4.Object.getPrototypeOf

用法:Object.getPrototypeOf(arr) === Array.prototype
Object.getPrototypeOf() 方法返回指定对象的原型

let arr = [];
console.log(Object.getPrototypeOf(arr) === Array.prototype); // true

5.Object.prototype.toString

用法:Object.prototype.toString.call(arr) === '[object Array]'
虽然Array也继承自Object,但js在Array.prototype上重写了toString,而我们通过toString.call(arr)实际上是通过原型链调用了

let arr = [];
console.log(Object.prototype.toString.call(arr) === '[object Array]'); // true

6.Array.isArray

用法:Array.isArray(arr)
ES6中新增了Array.isArray方法,IE8及以下不支持

let arr = [];
console.log(Array.isArray(arr)); // true