<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>set集合实践</title>
</head>
<body>
<div id="ad">
</div>
<div></div>
<script>
let arr = [1,2,2,3,1,4,5];
//数组去重
let arr2 = [... new Set(arr)];
console.log(arr2);
//交集
let arr3 = [2,3,2,4,5];
let arr4 = [4,5,6,7];
let arrSet4 = new Set(arr4);
let result = arr3.filter(item=>arrSet4.has(item));
console.log(result);
//并集
let arr5 = [2,3,2,4,5];
let arr6 = [4,5,6,7];
let result2 = [...new Set([...arr5, ...arr6])];
console.log(result2);
//差集
let arr7 = [2,3,2,4,5];
let arr8 = [4,5,6,7];
let arrSet8 = new Set(arr8);
let result3 = [...new Set(arr7.filter(item=>!arrSet8.has(item)))];
console.log(result3);
</script>
</body>
</html>