function mergerArr(arr1,arr2){
var flag;
for(var i = 0;i<arr1.length;i++){
flag = false;
for(var j=0;j<arr2.length;j++){
if(arr1[i] == arr2[j]){
flag = true;
break;
}
}
if(!flag){
arr2.push(arr1[i]);
}
}
return arr2;
}
var a = [1,2,3,4];
var b = [3,4,5,6];
var newArr = mergerArr(a,b);
console.log(newArr)
输出 [3,4,5,6,1,2];
时间: 2024-10-06 16:02:22