【发布时间】:2021-03-03 08:47:20
【问题描述】:
我有这样的数据结构:
const arr1 = [["name1", "123", "prop2"],["name2", "43", "prop22"], ["name3", "22", "prop3"]];
const arr2 = [[156, 154, "position report"],[173, 124, "position report"],[136, 154, "position report"]];
我希望最终的数组看起来像这样:
finalArr = [["name1", "123", "prop2",156, 154, "position report], ["name2", "43", "prop22",173, 124, "position report"],["name3", "22", "prop3", 136, 154, "position report"]]
基本上我想在一个新的最终数组中将 arr1 的子数组元素合并到 arr2 中。我曾尝试使用此代码,但它只合并 2 个数组而不是子元素
let newArr = [];
arr1.forEach((item) => {
arr2.forEach((element) => {
newArr.push({ ...item, element });
});
});
console.log(newArr);
任何仅使用 ES6 符号的想法?
【问题讨论】:
标签: javascript arrays ecmascript-6