数组对象通过键去重

<!DOCTYPE html>
<html>
<head>
<title>数组去重</title>
</head>
<body>
<script type="text/javascript">
var projectLineLis = [
{value: 1, label: "雪亮标品", $$hashKey: "067"},
{value: 2, label: "大数据", $$hashKey: "068"},
{value: 3, label: "大联动", $$hashKey: "069"},
{value: 4, label: "全科采集", $$hashKey: "06A"},
{value: 5, label: "铁路护路", $$hashKey: "06B"},
{value: 6, label: "平安中国", $$hashKey: "06C"},
{value: 7, label: "社会化服务", $$hashKey: "06D"},
{value: 1, label: "雪亮标品", $$hashKey: "06E"},
{value: 8, label: "12", $$hashKey: "06F"},
{value: 8, label: "45", $$hashKey: "06G"},
{value: 1, label: "雪亮标品", $$hashKey: "06H"},
{value: 2, label: "大数据", $$hashKey: "06I"},
{value: 3, label: "大联动", $$hashKey: "06J"},
]
function arrayUnique2(arr, name) {
var hash = {};
return arr.reduce(function (item, next) {
hash[next[name]] ? '' : hash[next[name]] = true && item.push(next);
return item;
}, []);
}
console.log(arrayUnique2(projectLineLis,'label'))
</script>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/xyyyy/p/9965893.html