开发者

javascript arrays, how to change this array structure

I have 3 arrays in javascript. I'd like to combine them all into 1 var, but name each item (like PHP's associate array). 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜