JS对象数组根据某字段去重

对象数组:

var  LocationInfoData =[ {_id: "60eea0b998da2545481b78c0", locationName: "澳门海事博物馆",  region: "澳门特别行政区/风顺堂区"},
{_id: "60eea0b398da2545481b66d5", locationName: "妈阁庙",  region: "澳门特别行政区/风顺堂区"},
 {_id: "60eea0b398da2545481b66c1", locationName: "圣奥斯定教堂",  region: "澳门特别行政区/风顺堂区"},
{_id: "60eea0b398da2545481b66d1", locationName: "圣老楞佐教堂",  region: "澳门特别行政区/风顺堂区"},
 {_id: "60eea0c098da2545481b8c4a", locationName: "郑家大屋",  region: "澳门特别行政区/风顺堂区"}]


        const res = new Map();
        var districts = LocationInfoData.filter((a) => !res.has(a.region) && res.set(a.region, 1));

你可能感兴趣的:(JS对象数组根据某字段去重)