如果有遇到一個數組中存儲多個對象,有部分對象的某一個鍵值是相同的,需要過濾掉重複項的實現方案
const arr =[
{
"count": 1095,
"month": "三月",
},
{
"count": 1106,
"month": "三月",
},
{
"count": 987,
"month": "四月",
},
{
"count": 1166,
"month": "四月",
},
{
"count": 753,
"month": "五月",
},
{
"count": 891,
"month": "五月",
}
];
const res = new Map();
const new2 = arr.filter(item => !res.has(item.month) && res.set(item.month, 1));
console.log(arr.length, new2);