将下面两数组合并
var arr1 = [1,2,3];
var arr2 = [4,5,6];
1.简单好理解
var arr3 = [];
//遍历arr1
for (var i = 0; i < arr1.length; i++) {
arr3.push(arr1[i]);
}
//遍历arr2
for (var j = 0; j < arr2.length; j++) {
arr3.push(arr2[j]);
}
console.log(arr3); //[1,2,3,4,5,6]
2.concat()方法
var arr1 =[1,2,3];
var arr2 = [4,5,6];
var arr3 = arr1.concat(arr2);
console.log(arr3); //[1,2,3,4,5,6]