Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript数组,如何更改此数组结构_Javascript_Jquery_Arrays - Fatal编程技术网

javascript数组,如何更改此数组结构

javascript数组,如何更改此数组结构,javascript,jquery,arrays,Javascript,Jquery,Arrays,我有3个javascript数组。我想将它们组合成1个变量,但要命名每个项目(如PHP的关联数组)。所以第一项是红色,第二项是绿色,第三项是蓝色。然后,我如何分别命名每个项目后 [[2, 1], [4, 1], [10, 1], [19, 1]], [[3, 1], [14, 1], [18, 1], [19, 1]], [[7, 1], [6, 1], [8, 1], [17, 1]] 你是说像这样的事吗 var combined = { red: [[2, 1], [4, 1],

我有3个javascript数组。我想将它们组合成1个变量,但要命名每个项目(如PHP的关联数组)。所以第一项是红色,第二项是绿色,第三项是蓝色。然后,我如何分别命名每个项目后

[[2, 1], [4, 1], [10, 1], [19, 1]],
[[3, 1], [14, 1], [18, 1], [19, 1]],
[[7, 1], [6, 1], [8, 1], [17, 1]]

你是说像这样的事吗

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]]
};

然后,您可以以
combined.red
combined.green
combined.blue

的形式访问数组。与PHP的关联数组类似,您也可以像
combined[“red”]
combined[“green”]
combined[“blue”
这样访问数组。