Array.indexOf vs Object's "in operator

JavaScript performance comparison

Revision 21 of this test case created

Info

Testing if access through Array.indexOf or Object's in Operator is faster.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr = [
      'that',
      'is',
      'some',
      'nice',
      'some',
      'test',
      'here',
      'they',
      'will',
      'not',
      'be',
      'found',
      'anywhere',
      'else'
    ]
   
    var obj = {
      'that': null,
      'is': null,
      'some': null,
      'nice': null,
      'test': null,
      'here': null,
      'they': null,
      'will': null,
      'not': null,
      'be': null,
      'found': null,
      'anywhere': null,
      'else': null
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Array - Find first element
arr.indexOf('that');
pending…
Object - Find first element
'that' in obj;
pending…
Array - Find last element
arr.indexOf('else');
pending…
Object - Find last element
'else' in obj;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment