3 回答

TA贡献1801条经验 获得超8个赞
如果您不关心销毁arr2,也不关心 的深层副本arr1[0],那么简单的方法unshift()可以做到:
const arr1 = [[1, 2, 3, 4], [5, 6, 7, 8]];
const arr2 = [['some1', 'some2'], ['some3', 'some4']];
arr2.unshift(arr1[0]);
console.log(JSON.stringify(arr2));
当然,这些确实是一些可能不适合您的情况的条件。

TA贡献1884条经验 获得超4个赞
使用 ES6 扩展运算符如下。
const arr1 = [[1, 2, 3, 4], [5, 6, 7, 8]];
const arr2 = [['some1', 'some2'], ['some3', 'some4']];
const finalArr = [arr1[0], ...arr2];
console.log(finalArr);
或者使用 concat 函数。
const arr1 = [[1, 2, 3, 4], [5, 6, 7, 8]];
const arr2 = [['some1', 'some2'], ['some3', 'some4']];
const finalArr = [arr1[0]].concat(arr2);
console.log(finalArr);

TA贡献1818条经验 获得超11个赞
const arr1 = [[1, 2, 3, 4], [5, 6, 7, 8]];
const arr2 = [['some1', 'some2'], ['some3', 'some4']];
cont finalArr = Array();
finalArr.push(arr1[0]);
finalArr.push(arr2[0]);
finalArr.push(arr2[1]);
您还可以遍历数组并动态推送它们。
添加回答
举报