声明JavaScript数组时,“Array()”和“[]”有什么区别?这样声明数组的真正区别是:var myArray = new Array();和var myArray = [];
3 回答
qq_花开花谢_0
TA贡献1835条经验 获得超7个赞
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;添加回答
举报
0/150
提交
取消
