What is the best way to do loops in JavaScript

前端 未结 9 1850
温柔的废话
温柔的废话 2020-12-13 00:35

I have stumbled into several methods of looping in JavaScript, what I like the most is:

for(var i = 0; i < a.length; i++){
    var element = a[i];
}
         


        
9条回答
  •  有刺的猬
    2020-12-13 01:22

    Just store the length in a variable first.

      var len = a.length;
      for (var i = 0; i < len; i++) {
        var element = a[i];
      }
    

提交回复
热议问题