isArray approaches

JavaScript performance comparison

Test case created by Louis Acresti

Info

Various ways to test if an object is an array.

Preparation code

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

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
Object.prototype.toString.call( test ) === '[object Array]';
Object.prototype.toString.call( obj ) === '[object Array]';
Object.prototype.toString.call( str ) === '[object Array]';
Object.prototype.toString.call( func ) === '[object Array]';
pending…
prototype flag method
test.array_ === true;
obj.array_ === true;
str.array_ === true;
func.array_ === true;
pending…

Compare results of other browsers

Revisions

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:

0 comments

Add a comment