IndexOf vs object lookup

Benchmark created on


Description

['a',b','c'].indexOf('a') !== -1

vs

!!({ a: 1 , b: 1 , c: 1 }).a

vs 'a' in { a: 1 , b: 1 , c: 1 }

Preparation HTML

<script>
  var arr = ['a', 'b', 'c'];
  
  var obj = {
   a: 1,
   b: 1,
   c: 1
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
if (arr.indexOf('a') !== -1) {}
ready
Object property access
if (obj.a) {}
ready
Object in
if ('a' in obj) {}
ready

Revisions

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