有几种方法可以有效地合并两个数组:
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];
let mergedArray = arr1.concat(arr2);
console.log(mergedArray); // [1, 2, 3, 4, 5, 6]
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];
let mergedArray = [...arr1, ...arr2];
console.log(mergedArray); // [1, 2, 3, 4, 5, 6]
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];
arr2.forEach(element => {
arr1.push(element);
});
console.log(arr1); // [1, 2, 3, 4, 5, 6]
这些方法都可以有效地合并两个数组,你可以根据自己的需求选择适合的方法。