Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.89 Safari/537.36
Chrome 102
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Object.hasOwnProperty 7529885.0 Ops/sec
Object in 6651291.0 Ops/sec
Array.indexOf 1112852.8 Ops/sec
direct 6666648.0 Ops/sec
Array includes 1108234.0 Ops/sec
Script Preparation code:
AخA
 
  var object = {},
      array = [],
      i, test = 1000;
  
  for (i = 0; i < 1000; i++) {
   object['something' + i] = true;
   array.push('something' + i);
  }
Tests:
  • Object.hasOwnProperty

     
    object.hasOwnProperty('something' + test)
  • Object in

     
    ('something' + test) in object
  • Array.indexOf

     
    array.indexOf('something' + test) !== -1
  • direct

     
    object['something' + test] === true
  • Array includes

     
    array.includes('something' + test)