美文网首页
1:对象数组根据对象某key值去重

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

作者: 悦耳的茶 | 来源:发表于2019-03-05 23:39 被阅读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);});

    相关文章

      网友评论

          本文标题:1:对象数组根据对象某key值去重

          本文链接:https://www.haomeiwen.com/subject/rlxzuqtx.html