built-in V8 function. It's fast, it's always right. This is part of ES5.
Checks if an object was created using an array constructor.
The method of underlining. Here is a snippet taken from their source
var toString = Object.prototype.toString, nativeIsArray = Array.isArray; _.isArray = nativeIsArray || function(obj) { return toString.call(obj) === '[object Array]'; };
This method takes an object and calls the Object.prototype.toString method on it. This will always return [object Array] for arrays.
In my personal experience, I believe that the toString method is the most efficient, but it is not as short and cannot be read as instanceof Array , but it is not as fast as Array.isArray , but this code is ES5 and I try to avoid using it for portability.
I personally would recommend using underscore , which is a library with common utilities in it. It has many useful features that DRY makes your code.
Raynos May 9 '11 at 19:48 2011-05-09 19:48
source share