How to do it more efficiently?

前端 未结 6 500
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 08:58

Let\'s imagine we should get some data...

var data = [];

//some code omitted that might fill in the data (though might not)

Then we need t

6条回答
  •  执笔经年
    2021-01-06 09:24

    I usually don't check the length before iteration. As a matter of fact, the for loop itself will check the length on each iteration.

    There's no performance overhead worth mentioning. In case length was = 0, the only extra instruction would be that a new int i would be declared in the memory. You need thousands of those to feel a millisecond impact.

提交回复
热议问题