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));
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容