在块中水平附加多维数组 [英] Append Multi-Dimension Arrays Horizontally in Blocks

查看:43
本文介绍了在块中水平附加多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个多维数组,希望将它们水平连接.将多维数组视为表,我想通过水平堆叠将它们追加.

I have several Multi-Dimension Arrays, that I wish to concatenate horizontally. Thinking of the Multi-Dimension Arrays as tables, I want to append each by stacking them horizontally.

我尝试使用地图和嵌套地图,但是我无法使其完全按照所述方式工作.

I have tried to use map and nested map, but I cannot get it work exactly as described.

var arr1 = [["A1","B1","C1","D1"],["A2","B2","C2","D2"]]
var arr2 = [["E1","F1","G1","H1"],["E2","F2","G2","H2"]]

我如何将它们合并到输出将是的单个数组中

how can I merge these into a single array where the output would be

var arrMerged = [["A1","B1","C1","D1","E1","F1","G1","H1"],["A2","B2","C2","D2","E2","F2","G2","H2"]]

推荐答案

以下是带有map的版本.

const arr1 = [["A1","B1","C1","D1"],["A2","B2","C2","D2"]]
const arr2 = [["E1","F1","G1","H1"],["E2","F2","G2","H2"]];

const out = arr1.map((arr, i) => {
  return arr.concat(arr2[i]);
});

console.log(out);

这篇关于在块中水平附加多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆