1:对象数组根据对象某key值去重

2019-03-05  本文已影响0人  悦耳的茶

let arr = [{showId:'C',age:'11'}, {showId:'A',age:'11'},{showId:'B',age:'11'}, {showId:'B',age:'11'},{showId:'B',age:'12'},{showId:'B',age:'13'}];

// 根据showId去重到新数组newArr

constnewArr = [];

 arr.forEach(item=>{

          // 过滤,如果有重复项就添加到过滤数组,那么长度就不为0就不会推入新数组。

          // 如果没有重复项长度就为0就推入新数组。

          newArr.filter(m=>m.showId === item.showId).length ===0&& newArr.push(item);});

上一篇下一篇

猜你喜欢

热点阅读