Home > Article > Web Front-end > Methods to determine whether a variable is an array, function or object type in JavaScript_javascript skills
Array
Array.isArray in ECMAScript5 is the native method for judging arrays, supported by IE9 and above. For compatibility reasons, in browsers that do not have this method, you can use Object.prototype.toString.call(obj) === '[object Array]' instead.
Function
The simplest and best-performing method is typeof obj == 'function'. Considering the bugs in some versions of browsers, the most reliable method is Object.prototype.toString.call(obj) === '[object Function]'.
Object
In JavaScript, complex types are objects, and functions are also objects. Using typeof on the above two, you can get 'object' and 'function' respectively. In addition, null values must be excluded, because typeof null also returns 'object'.
The above is the entire content of this article, I hope you all like it.