首页 > 编程语言 > 详细

数组里的对象去重

时间:2018-01-08 11:44:14      阅读:264      评论:0      收藏:0      [点我收藏+]
function unique(arr){
    // 遍历arr,根据对象的属性categoryCode去重
      var hash = {};
      arr = arr.reduce(function(item, next) {
          hash[next.categoryCode] ? ‘‘ : hash[next.categoryCode] = true && item.push(next);
          return item
      }, [])
      console.log(arr);
    }

 

数组里的对象去重

原文:https://www.cnblogs.com/JennyGao/p/8241826.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!