Using the push method or .length when adding to array?

后端 未结 6 1785
慢半拍i
慢半拍i 2020-12-31 08:26

What are the downsides to doing:

var myArray = [];
myArray[myArray.length] = val1;
myArray[myArray.length] = val2;

instead of:



        
6条回答
  •  隐瞒了意图╮
    2020-12-31 08:41

    I've generally thought length assignment was faster. Just found Index vs. push performance which backs that up; for my Chrome 14 browser anyway, over a single test run. However there is not much in it in Chrome.

提交回复
热议问题