数组里的对象去重

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);
    }

 

posted @ 2018-01-08 11:26  JennyGao  阅读(254)  评论(0编辑  收藏  举报