根据教程中,我读,如果你想创建一个表有5列3行表示这样的数据...JavaScript的数组
45 4 34 99 56
3 23 99 43 2
1 1 0 43 67
...它说,你可以使用以下阵列
var table = new Array(5)
table[0] = [45, 4, 34, 99, 56];
table[1] = [3, 23, 99, 43, 2];
table[2] = [1, 1, 0, 43, 67];
但我本来期望它是这样
var table = new Array(3)
table[0] = [45, 4, 34, 99, 56];
table[1] = [3, 23, 99, 43, 2];
table[2] = [1, 1, 0 43, 67]
如果,在本教程中,var table
最初被声明为一个包含5个元素的数组,然后第一个(table [0]),second(table [1])和third(table [2])被数据填充,其他两个元素会发生什么最初使用新的Array(5)在数组中设置。为什么你需要使用5?
这是一个在线教程吗?如果是的话,你可以发布一个链接? – JaredPar 2011-03-02 01:05:00
获得更好的教程 - 你真的不需要在Javascript中使用'new Array(3)'。总是使用'var table = [];' - 预先分配大小并没有什么好处。 – Pointy 2011-03-02 01:05:35
@JaredPar它来自一本书,叫做JavaScript cookbook – mjmitche 2011-03-02 01:13:03