代码语言:javascript复制数组去重方法 arr //将要去重的数组 model //判断数组去重的字段
function unique ( arr,model ) { //数组去重
let res = [arr[0]];
console.log(res)
for (let i = 0; i < arr.length; i ) {
let repeat = false;
for (let j = 0; j < res.length; j ) {
if (arr[i][model] == res[j][model]) {
repeat = true;
break;
}
}
if (!repeat) {
res.push(arr[i]);
}
}
return res;
}