Nonsense not much brush! Let’s get straight to the point.

1. Use the built-in Array method: array.isarray ()

Log (array.isarray (arr)) //true console.log(array.isarray (obj)) //falseCopy the code

Let arr=[] let arr=[

Console. log(arr) // Have a constructor:f Array()Copy the code

This is an OBJ object

Log (arr.constructor===Array) //true console.log(obj.constructor==Array) //falseCopy the code

The instanceof operator is used to check whether the constructor’s prototype property is present in the prototype chain of an instance object

Log (arr instanceof Array) //true console.log(obj instanceof Array) //falseCopy the code

4. Use isProtoTypeof ()(this method is used to determine if an object exists on an object’s prototype chain)

let arr = []; / / the above mentioned is equivalent to the let arr = new Array () the console. The log (Array) prototype) isPrototypeOf (arr)); // trueCopy the code

5. Call toString () across the prototype chain

Every Object that inherits Object has a toString method, which, if not overridden, returns [Object type], where type is the type of the Object. But when the variable type is not an object, toString returns a string of data content, so we need to use call or apply to change the execution context of toString

When not changing scope:

Use the call

const an = ['Hello','An'];
an.toString(); // "Hello,An"
Object.prototype.toString.call(an); // "[object Array]"

Copy the code