Javascript array best practice to use [] instead of new array?

前端 未结 5 1135
醉话见心
醉话见心 2020-12-31 04:08

I read at many tutorials that the current best practices to create a new javascript array is to use

var arr = [] 

instead of



        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 04:37

    Also note that doing:

    var x = [5];
    

    Is different than doing:

    var x = new Array(5);
    

    The former creates an initializes an array with one element with value of 5. The later creates an initializes an array with 5 undefined elements.

提交回复
热议问题