数组对象通过键去重
Posted xyyyy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数组对象通过键去重相关的知识,希望对你有一定的参考价值。
<!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>
以上是关于数组对象通过键去重的主要内容,如果未能解决你的问题,请参考以下文章