Run details:
Mozilla/5.0 (Linux; Android 12; Pixel 4a) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Mobile Safari/537.36
Chrome Mobile 101
Android
Mobile
3 years ago
Test name Executions per second
Object.hasOwnProperty 1585450.5 Ops/sec
Object in 1425924.5 Ops/sec
Array.indexOf 346274.5 Ops/sec
direct 1454480.4 Ops/sec
Array includes 344808.4 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)