js数组去重
js两个数组去重 (对象)
for (var i = 0; i < arr1.length; i++) {
var flag = 1;
for (var j = 0; j < arr2.length; j++) {
if (arr2[j].name == arr1[i].name) {
flag = 0;
}
}
flag === 1 ? arr2.push(arr1[i]) : false;
}
console.log(arr2);
js两个数组去重 重复的不保留
var arr1 = [1,2,3,4,5,6,7,8,9,10];
var arr2 = [1,2,3,4,5,6,7,8];
for (var i = 0; i < arr1.length; i++) {
var index = arr2.indexOf(arr1[i]);
if (index !== -1) {
arr1.splice(i, 1);
arr2.splice(index, 1);
i = -1;
}
}
console.log(arr1.concat(arr2));
js去重 重复的保留一份
//去重复
function qctimes(a, arr) {
arr.forEach(function (item) {
return a.includes(item) ? '' : a.push(item);
});
return a;
}