instanceOf Array vs Array.isArray() (v17)

Revision 17 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]];

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
call test
var toClass = {}.toString;
toClass.call(objAnswer.answer.value) === Array
ready

Revisions

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