作者:perfect--林榆盛 | 来源:互联网 | 2023-06-09 13:35
基本数据类型去重arr[newSet(arr)];这个只能去重基本数据类型引用数据类型去重varobj{};arrarr(function(item,next){obj[ne
基本数据类型去重
arr = [...new Set(arr)]; //这个只能去重基本数据类型
引用数据类型去重
var obj = {};
arr = arr(function (item, next) {
obj[next.ID] ? "" : (obj[next.ID] = true && item.push(next));
return item;
}, []);
这是利用reduce方法遍历数组,reduce第一个参数是遍历需要执行的函数,第二个参数是item的初始值