Array
In ECMAScript5, Array.isarray is the primary method of judging arrays, IE9 and above support. With compatibility in mind, in browsers without this method, you can use Object.prototype.toString.call (obj) = = ' [Object Array] ' instead.
Copy Code code as follows:
var IsArray = Array.isarray | | function (obj) {
return Object.prototype.toString.call (obj) = = ' [Object Array] ';
}
Function
The simplest and best way to do this is to typeof obj = ' function '. Given the bugs that exist in some version browsers, the most plausible approach is Object.prototype.toString.call (obj) = = ' [Object Function] '.
Copy Code code as follows:
var isfunction = function (obj) {
return Object.prototype.toString.call (obj) = = ' [Object Function] ';
}
if (typeof/./!= ' function ' && typeof int8array ' object ') {
isfunction = function (obj) {
return typeof obj = = ' function ';
}
}
Object
Complex types are objects in JavaScript, and functions are objects. Using typeof for the above 2 people, you can get ' object ' and ' function ' respectively. In addition, the case of null values is excluded, because typeof null is also ' object '.
Copy Code code as follows:
var isobject = function (obj) {
var type = typeof obj;
return type = = ' function ' | | Type = = = ' object ' &&!! Obj
}
The above is the entire content of this article, I hope you can enjoy.