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

前端 未结 5 1133
醉话见心
醉话见心 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:21

    To create Array without Length

    var arr = [];
    

    To create Array with Length more dynamically

    var arr;
    ( arr = [] ).length = 10;  // 10 is array length
    

    To create Array with Length less dynamically

    var arr = [];
    arr.length = 10;
    

提交回复
热议问题