instanceOf Array vs Array.isArray() vs toString (v5)

Revision 5 of this benchmark created by Ezra Olubi 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]];

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
ToString.call of A
toString.call(A) === '[object Array]' ? true : false
ready
ToString.call of B
toString.call(B) === '[object Array]' ? true : false
ready
ToString.call of C
toString.call(C) === '[object Array]' ? true : false
ready

Revisions

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