What’s the difference between “Array()” and “[]” while declaring a JavaScript array?

后端 未结 18 1706
生来不讨喜
生来不讨喜 2020-11-21 12:00

What\'s the real difference between declaring an array like this:

var myArray = new Array();

and

var myArray = [];
<         


        
18条回答
  •  深忆病人
    2020-11-21 12:41

    Using the Array constructor makes a new array of the desired length and populates each of the indices with undefined, the assigned an array to a variable one creates the indices that you give it info for.

提交回复
热议问题