js2個數組合並並去重
阿新 • • 發佈:2018-12-03
//合併並去重
function MergeArray(arr1, arr2) {
var _arr = new Array();
for (var i = 0; i < arr1.length; i++) {
if (arr1[i] != "") {
_arr.push(arr1[i]);
}
}
for (var i = 0; i < arr2.length; i++) {
var flag = true;
for (var j = 0; j < arr1.length; j++) {
if (arr2[i] == arr1[j]) {
flag = false;
break;
}
}
if (flag && arr2[i] != "") {
_arr.push(arr2[i]);
}
}
return _arr;
}