美文网首页
js对象数组去重

js对象数组去重

作者: 段煜华 | 来源:发表于2020-04-19 12:45 被阅读0次
const arr=[{id:1,value:'bob'},{id:1,value:'bob'},{id:1,value:'bob'},{id:1,value:'lucy'},{id:1,value:'lucy'},{id:2,name:'lucy'},{id:2,name:'张三'}]
const newArr = arr.reduce((result, item) => {
        if (!result.find(x => x.value === item.value)) {
          result.push(item);
        }
        return result;
}, []);

相关文章

网友评论

      本文标题:js对象数组去重

      本文链接:https://www.haomeiwen.com/subject/kclmoctx.html