isArray approaches (v6)

Revision 6 of this benchmark created on


Description

Various ways to test if an object is an array.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
toString method
var arr = '[object Array]';
Object.prototype.toString.call(test) === arr;
Object.prototype.toString.call(obj) === arr;
Object.prototype.toString.call(str) === arr;
Object.prototype.toString.call(func) === arr;
ready
prototype flag method
test.array_ === true;
obj.array_ === true;
str.array_ === true;
func.array_ === true;
ready
instanceof
test instanceof Array;
obj instanceof Array;
str instanceof Array;
func instanceof Array;
ready
jQuery
$.isArray(test);
$.isArray(obj);
$.isArray(str);
$.isArray(func);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.