js数组对象去重:
<html>
<head>
<title>我的第一个 HTML 页面</title>
</head>
<body>
</body>
<script>
let obj = [{
id: 1,
type: 1,
},
{
id: 2,
type: 2,
},
{
id: 2,
type: 2,
},
{
id: 2,
type: 2,
},
{
id: 2,
type: 2,
},
{
id: 3,
type: 3,
},
{
id: 1,
type: 1,
},
]
let arry = [1, 2]
function unique(arr) {
const res = new Map();
return arr.filter((arr) => !res.has(arr.type) && res.set(arr.type, 1));
}
obj = unique(obj);
console.log(obj);
obj.forEach(i => {
arry.forEach(item => {
if (item == i.type) {
console.log(item)
}
})
})
</script>
</html>
原文:https://www.cnblogs.com/hudunyu/p/13969702.html