美文网首页
JS对象数组根据某字段去重

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

作者: 醉酒的姑娘 | 来源:发表于2021-09-02 16:44 被阅读0次

对象数组:

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对象数组根据某字段去重

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