isArray approaches

JavaScript performance comparison

Test case created by Louis Acresti


Various ways to test if an object is an array.

Preparation code

Benchmark.prototype.setup = function() {
    Array.prototype.array_ = true;
    var test = [],
        obj = {},
        str = 'blah blah',
        func = function(){};

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
toString method test ) === '[object Array]'; obj ) === '[object Array]'; str ) === '[object Array]'; func ) === '[object Array]';
prototype flag method
test.array_ === true;
obj.array_ === true;
str.array_ === true;
func.array_ === true;

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:


Comment form temporarily disabled.

Add a comment