js 对象数组去重

Posted on 2020-09-18 15:23  zkx4213  阅读(192)  评论(0编辑  收藏  举报
var arr = [
  {   key: '01',   value: '乐乐'   }, { key: '02', value: '博博' }, { key: '03', value: '淘淘' },{ key: '04', value: '哈哈' },{ key: '01', value: '乐乐' }

];
//数组去重
uniqueArr(arr) {
var obj = {};
arr = arr.reduce(function(item, next) {
obj[next.key] ? '' : obj[next.key] = true && item.push(next);
return item;
}, []);
return arr;
}

console.log(uniqueArr(arr))
 

Copyright © 2024 zkx4213
Powered by .NET 9.0 on Kubernetes