What's the real difference between declaring an array like this:(声明这样的数组之间的真正区别是什么:)
var myArray = new Array();
var myArray = [];
There is a difference, but there is no difference in that example.(有所不同,但在该示例中没有区别。)
new Array()
x = new Array(5); alert(x.length); // 5
var a = [], // these are the same b = new Array(), // a and b are arrays with length 0 c = ['foo', 'bar'], // these are the same d = new Array('foo', 'bar'), // c and d are arrays with 2 strings // these are different: e = [3] // e.length == 1, e[0] == 3 f = new Array(3), // f.length == 3, f[0] == undefined ;
new Array(5)
undefined
Array
array.length
1.4m articles
1.4m replys
5 comments
57.0k users