ES6|ES6 数组去重,数组对象去重

// 数组对象去重 { const arr = [ { name:'zhangsan', age:12 }, { name:'lisi', age:14 }, { name:'zhangsan', age:12 }, { name:'lisi', age:14 }, { name:'zhangsan', age:12 }, ]// 根据 age 去重 // 方法一 const age = 'age'; const r = arr.reduce((all, next) => all.some((atom) => atom[age] == next[age]) ? all : [...all, next],[]); console.log(r);

// 数组去重 { const arr = [1,2,3,4,1,23,5,2,3,5,6,7,8,undefined,null,null,undefined,true,false,true,'中文','','','hello','中文']; //第一种 const r = [...new Set(arr)];

【ES6|ES6 数组去重,数组对象去重】更多参考:了解更多点击链接

    推荐阅读