Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.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/2/jquery/75.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,我有一个这样的数组 [ [ "text1", "text2", "text3", "text4", "text5" ], [ "Rtext1", "Rtext2", "Rtext3", "Rtext4", "Rtext5" ], [ "1", "2", "3", "4", "5" ] ] 我需要使用JavaScript将其转换为以下格式 [ [

我有一个这样的数组

[
  [
    "text1",
    "text2",
    "text3",
    "text4",
    "text5"
  ],
  [
    "Rtext1",
    "Rtext2",
    "Rtext3",
    "Rtext4",
    "Rtext5"
  ],
  [
    "1",
    "2",
    "3",
    "4",
    "5"
  ]
]
我需要使用JavaScript将其转换为以下格式

[
  [
    "text1",
    "Rtext1",
    "1"
  ],
  [
    "text2",
    "Rtext2",
    "2"
  ],
  [
    "text3",
    "Rtext3",
    "3"
  ],
  [
    "text4",
    "Rtext4",
    "4"
  ],
  [
    "text5",
    "Rtext5",
    "5"
  ]
]
使用JavaScript或jQuery实现这一点的最佳方法是什么

我使用多个for循环在数组中循环,但无法掌握其中的诀窍

使用方法
var数据=[
[
“文本1”,
“文本2”,
“文本3”,
“文本4”,
“文本5”
],
[
“Rtext1”,
“Rtext2”,
“Rtext3”,
“Rtext4”,
“Rtext5”
],
[
"1",
"2",
"3",
"4",
"5"
]
];
var-res=[];
data.forEach(函数(ele){
要素forEach(功能(v,i){
res[i]=res[i]| |[];//如果未定义,则定义内部数组
res[i].push(v);//将值推送到数组
})
});

控制台日志(res)以下是您的操作方法

var x=[
[
“文本1”,
“文本2”,
“文本3”,
“文本4”,
“文本5”
],
[
“Rtext1”,
“Rtext2”,
“Rtext3”,
“Rtext4”,
“Rtext5”
],
[
"1",
"2",
"3",
"4",
"5"
]
];
var a=x[0];
var b=x[1];
var c=x[2];
var finalAra=[];

for(var i=0;i听起来像是在做数组压缩。这在函数式编程中非常常见,如果您已经使用了该库或不需要重新实现该功能,甚至还有一个内置项可以帮您完成

_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
// => [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]

请显示您尝试的代码。