Array
ECMAScript5 Array.isarray is the native method of judging arrays, IE9 and above support. For compatibility, in browsers that do not have this method, you can use Object.prototype.toString.call (obj) = = = ' [Object Array] ' instead.
var function (obj) { return Object.prototype.toString.call (obj) = = = ' [Object Array] ';}
Function
The simplest and best-performing approach is to typeof obj = = ' function '. The most reliable way to consider the bugs of some version browsers is Object.prototype.toString.call (obj) = = = ' [Object Function] '.
var function (obj) { return Object.prototype.toString.call (obj) = = = ' [Object Function] ';} if (typeoftypeof Int8array! = ' object ') {function(obj) { return typeof obj = = ' function '; }}
Note: In IE678, the native method for DOM objects, whether using typeof or Object.prototype.toString, is to return object instead of function. This is because in these browsers, the JScript engine is implemented separately and is not integrated into the browser kernel. IE9 after the JScript engine enters the browser kernel, this method can correctly identify the native methods of the DOM.
Object
In JavaScript, a complex type is an object, and a function is an object. For the above 2 use typeof, you can get ' object ' and ' function ' separately. Also, the case of null values is excluded, because typeof null gets the ' object ' as well.
var function (obj) { vartypeof obj; return Type = = = ' function ' | | Type = = = ' object ' &&!! obj;}
How to tell if a variable is an array, a function, or an object type in JavaScript