check if variable is array

JavaScript performance comparison

Test case created by sorin

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var A = [1, 2, 3, 4, 5],
    B = ['a', 'b', 'c', 'd', 'e'],
    C = [
      [1, 2],
      [3, 4],
      [5, 6],
      [7, 8],
      [9, 10]
    ],
    D = "asdasd",
    E = 12414,
    F = {
      a: 'a',
      b: 1
    };

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Instance of Array
(A instanceof Array &&
  B instanceof Array &&
  C instanceof Array && !(D instanceof Array) && !(E instanceof Array) && !(F instanceof Array)) ? true : false;
pending…
IsArray
(Array.isArray(A) &&
  Array.isArray(B) &&
  Array.isArray(C) && !(Array.isArray(D)) && !(Array.isArray(E)) && !(Array.isArray(F))) ? true : false;
pending…
Constructor
(A.constructor === Array &&
  B.constructor === Array &&
  C.constructor === Array && !(D.constructor === Array) && !(E.constructor === Array) && !(F.constructor === Array)) ? true : false;
pending…

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

Compare results of other browsers

0 Comments