js2个数组合并并去重

时间:2022-09-03 17:43:49
 //合并并去重
        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;
        }