reduce json对象数组去重 用法 二维变一维并去重

1             this.menuList = this.roles.map(item=>{
2               let hash={};
3               return item.privileges.reduce((arr,item)=>{
4                 return (Array.isArray(arr) ? arr : arr.resources).concat(item.resources);
5               },[]).reduce((item, next) => {
6                 hash[next.id] ? '' : hash[next.id] = true && item.push(next);
7                 return item;
8               }, []);
9             });

 

posted @ 2017-12-05 10:37  小猪宿州  阅读(410)  评论(1编辑  收藏  举报