for vs forEach vs for-of

Edit on GitHub

perfomance of for - foreach - for-of

Setup

var arr = [1,2,3,4,5,6,7,8,9,0]

Tests

  • for

    for (var i = 0, len = arr.length; i < len; i++) {
      var item = arr[i];
      item + 1;
    }
  • forEach

    arr.forEach(function(item) {
      item + 1;
    });
  • for-of

    for (var item of arr) {
      item + 1;
    }