Run details:
Mozilla/5.0 (Linux; Android 10; LYA-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.93 Mobile Safari/537.36
Chrome Mobile 88
Android
Mobile
3 years ago
Test name Executions per second
For In 399.3 Ops/sec
Object keys forEach 508.9 Ops/sec
Script Preparation code:
AخA
 
var obj = new Object()
var keys = (new Array(100)).fill(0).map((x, i) => { return i + 1 })
keys.forEach((x) => { obj['prop' + x] = x })
Tests:
  • For In

     
    for (var key in obj) {
      if (obj.hasOwnProperty(key)) console.log(obj[key])
    }
  • Object keys forEach

     
    Object.keys(obj).forEach(key => console.log(obj[key]))