简体   繁体   English

声明二维数组是否有捷径?

[英]Is there a shorthand for declaring a 2 dimensional array?

I am working with 2 dimensional arrays and I need a way to declare the number of inner arrays. 我正在使用二维数组,我需要一种方法来声明内部数组的数量。 Right now I'm using something like this: 现在我正在使用这样的东西:

var purchasePermutationP0Array = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];

which has 28 inner brackets. 有28个内支架。 What I want is to be able to declare how many inner brackets there are without using so many "[]". 我想要的是能够声明有多少个内括号而无需使用太多“ []”。 Is there a way to do that in javascript? 有没有办法做到这一点的JavaScript? Something like: 就像是:

var purchasePermutationP0Array = [new Array [28]]?

Thanks for your help. 谢谢你的帮助。

You can use a while loop- 您可以使用while循环-

var i=0, purchasePermutationP0Array = [];
while(i++<28)purchasePermutationP0Array.push([]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM