instanceOf Array vs Array.isArray() (v19)

Revision 19 of this benchmark created by ZAlexz 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 string value",
    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
IsArray A
Array.isArray(A) ? true : false;
ready
Constructor of A
A.constructor === Array ? true : false;
ready
Array-only method check
A.reduceRight ? true : false;
ready
String typeof
typeof B ==='string' ? true : false;
ready
constructor check
B.constructor === String ? true : false;
ready

Revisions

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