Object hasOwnProperty vs Array indexOf (v4)

Revision 4 of this benchmark created on


Preparation HTML

<script>
  var object = {},
      array = [],
      i, test = 1001;
  
  for (i = 0; i < 1000; i++) {
   object['something' + i] = true;
   array.push('something' + i);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
object.hasOwnProperty
object.hasOwnProperty('something' + test)
ready
array.indexOf
array.indexOf('something' + test) !== -1
ready
in
('something' + test) in object
ready
direct
object['something' + test] === true
ready
array hasPrperty
array.hasOwnProperty('something' + test)
ready

Revisions

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