1. instanceof
Use the instanceof operator to determine,instanceof
const arr= []
instanceof arr === Array // true
Copy the code
2. Array.isArray
Use ES5 method array. isArray keyword judgment, function details
const arr = []
Array.isArray(arr) // true
const obj = {}
Array.isArray(obj) // false
Copy the code
3. Object.prototype.isPrototypeOf
The isPrototypeOf() method is used to test whether an Object exists on the prototype chain of another Object.
const arr = []
Object.prototype.isPrototypeOf(arr, Array.prototype) // true
Copy the code
4. Object.getPrototypeOf
The object.getProtoTypeof () method returns the Prototype of the specified Object (the value of the internal [[Prototype]] property).
const arr = []
Object.getPrototypeOf(arr) === Array.prototype // true
Copy the code
5. Object.prototype.toString
Call toString() using the Object prototype call or apply method to see if toString() is [Object Array]
const arr = []
Object.prototype.toString.call(arr) === '[object Array]' // true
const obj = {}
Object.prototype.toString.call(obj) // "[object Object]"
Copy the code