instanceOf Array vs Array.isArray() (v10)

Revision 10 of this benchmark created on


Description

Comparison between the different ways of checking if a value is an array.

Setup

var A = [1, 2, 3, 4, 5],
      B = ['a', 'b', 'c', 'd', 'e'],
      C = [
        [1, 2],
        [3, 4],
        [5, 6],
        [7, 8],
        [9, 10]
      ];
    Array.prototype.iArray = true;

Test runner

Ready to run.

Testing in
TestOps/sec
Instance of Array A
A instanceof Array ? true : false;
ready
Instance of Array B
B instanceof Array ? true : false;
ready
Instance of Array C
C instanceof Array ? true : false;
ready
IsArray A
Array.isArray(A) ? true : false;
ready
IsArray B
Array.isArray(B) ? true : false;
ready
IsArray C
Array.isArray(C) ? true : false;
ready
Constructor of A
A.constructor === Array ? true : false;
ready
Constructor of B
B.constructor === Array ? true : false;
ready
Constructor of C
C.constructor === Array ? true : false;
ready
Prototype A
A.iArray || false
ready
Prototype B
B.iArray || false
ready
Prototype C
C.iArray || false
ready
Length Property A
A.length !== void 0
ready
Length Property B
B.length !== void 0
ready
Length Property C
C.length !== void 0
ready

Revisions

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