【js】数组对象去重

let msgArr= [
     {msgID: 0, msg: "hello"},
     {msgID: 1, msg: "hi"},
     {msgID: 1, msg: "h"},
     {msgID: 2, msg: "hi"},
     {msgID:3, msg: "nihao"},
     {msgID: 3, msg: "what"},   
];
 let arr = msgArr;
              let obj = {};
                        let newArr = arr.reduce((cur, next) => {
                            obj[next.msgID] ? "" : obj[next.msgID] = true && cur.push(next);
                            return cur;
                        }, [])
                        console.log("----", newArr)

  数组对象去重

原文地址:https://www.cnblogs.com/522040-m/p/13786423.html