Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Chrome 104
Mac OS X 10.15.7
Desktop
2 years ago
Test name Executions per second
for..of 11007710.0 Ops/sec
for..in 869422.4 Ops/sec
for 652991.1 Ops/sec
foreach 8610514.0 Ops/sec
Script Preparation code:
AخA
 
var arr = [12342, 342, 3423, 432, 432, 423, 43, 3, 1, 321, 323, 1, 31, 31, 31, 231, 31, 31];
Tests:
  • for..of

     
    const narr = [];
    for(const item of arr){
      narr.push(item)
    }
  • for..in

     
    const narr = [];
    for(const item in arr){
      narr.push(arr[item])
    }
  • for

     
    const narr = [];
    for(let i=0; i<arr.length; i++){
      narr.push(arr[i])
    }
  • foreach

     
    const narr = [];
    arr.forEach( e => narr.push(e));