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 IsArray = Array.isarray | | 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 isfunction = function (obj) {return Object.prototype.toString.call (obj) = = = ' [Object function] ';} if (typeof/./! = ' function ' && typeof int8array! = ' object ') {isfunction = function (obj) {return typeo F obj = = ' function '; }}
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 isobject = function (obj) {var type = typeof obj; return type = = = ' function ' | | Type = = = ' object ' &&!! obj;}
How to tell if a variable is an array, function, or object type in JavaScript