If this helps, here is how to do it in jQuery.isArray :
isArray: Array.isArray || function( obj ) { return jQuery.type(obj) === "array"; } type: function( obj ) { return obj == null ? String( obj ) : class2type[ toString.call(obj) ] || "object"; }
ToString:
toString = Object.prototype.toString
class2type is an associative array that is initialized as:
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) { class2type[ "[object " + name + "]" ] = name.toLowerCase(); });
If this is any indication, jQuery uses your first method and thoroughly tests it.
source share