How to do it more efficiently?

前端 未结 6 563
隐瞒了意图╮
隐瞒了意图╮ 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:17

    If data has no items, then the data.lenght will be 0. Thus your loop will never fire as i = 0 is already less than the number of items in the array. Therefore, option 2 is fine.

    However, in doing managed code, you probably would want to check for a NULL object before calling .length on that object.

提交回复
热议问题