javascript - 将两个数组组合成对
问题描述
我有两个想要组合的数组,但在搜索中我只能找到Array.concat
.
let a = [1,2,3,4,5]
let b = [6,7,8,9,10]
我如何结合这些来创建以下内容?
let combine = [
[1,6],
[2,7],
[3,8],
[4,9],
[5,10]
]
解决方案
如果两个数组的长度相同,则可以执行以下操作:
let a = [1,2,3,4,5]
let b = [6,7,8,9,10]
let combine = a.map((e, i) => [e, b[i]]);
console.log(combine);
推荐阅读
- python - 当您不知道先前的密钥时,从 data:dict 中获取
- python-3.x - 如何计算python中数组中重复项的数量?
- javascript - 给定此哈希函数、预期输出和输入字符串的长度,我如何找到返回给定结果的输入字符串?
- c - 在 C Linux 中将二进制文件转换为可读的文本文件
- javascript - 在 ionic 4 中使用 .js 文件
- arrays - React native expo:如何使用 fetch、POST 方法发送到 json 数组
- java - 为什么 ScheduledThreadPoolExecutor 不提供有限队列?
- konvajs - 如何使用 KonvaJs 插件获取多边形等形状的中心点?
- dialogflow-es - 如何将分数作为一个实体捕获?
- reactjs - React:我们可以用 props 扩展 styled-components 吗?