[英]javascript arrays, how to change this array structure
I have 3 arrays in javascript. 我在javascript中有3个数组。 I'd like to combine them all into 1 var, but name each item (like PHP's associate array). 我想将它们全部组合成1 var,但是为每个项目命名(就像PHP的关联数组一样)。 So the first item is red, second is green, third is blue. 所以第一项是红色,第二项是绿色,第三项是蓝色。 And then how do I call each item separately after? 然后如何分别调用每个项目?
[[2, 1], [4, 1], [10, 1], [19, 1]],
[[3, 1], [14, 1], [18, 1], [19, 1]],
[[7, 1], [6, 1], [8, 1], [17, 1]]
Do you mean something like this? 你的意思是这样的吗?
var combined = {
red: [[2, 1], [4, 1], [10, 1], [19, 1]],
green: [[3, 1], [14, 1], [18, 1], [19, 1]],
blue: [[7, 1], [6, 1], [8, 1], [17, 1]]
};
Then you can access the arrays as combined.red
, combined.green
, and combined.blue
. 然后你就可以访问数组作为combined.red
, combined.green
和combined.blue
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.