最简单的js数组去重方法

2024年07月31日 建站教程

var county =[
	{name: "鹿城区", value: 8340363, code: "330302"},
	{name: "龙湾区", value: 576804, code: "330303"},
	{name: "瓯海区", value: 14376314, code: "330304"},
	{name: "洞头区", value: 305933, code: "330305"},
	{name: "永嘉县", value: 1034338, code: "330324"},
	{name: "永嘉县", value: 1034338, code: "3303241"},
	{name: "平阳县", value: 1262985, code: "330326"},
	{name: "苍南县", value: 917294, code: "330327"},
	{name: "文成县", value: 211791, code: "330328"},
	{name: "文成县", value: 211791, code: "330328"},
	{name: "泰顺县", value: 230159, code: "330329"},
	{name: "瑞安市", value: 897806, code: "330381"},
	{name: "乐清市", value: 3829048, code: "330382"},
	{name: "龙港市", value: 417067, code: "330383-core"},
	{name: "龙港市", value: 417067, code: "330383"}
]
//去重
const newArr = new Map()
county = county.filter((a) => !newArr.has(a.name) && newArr.set(a.name, 1))
console.log('去重输出', county)

本文链接:http://so.lmcjl.com/news/9585/

展开阅读全文
相关内容