forked from ygs-code/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set.html
50 lines (43 loc) · 1.04 KB
/
Set.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
let set6 = new Set([1, 2, 2, 3, 4, 3, 5])
console.log('distinct 1:', set6)
//数组去重
let arr1 = [1, 2, 3, 4]
let arr2 = [2, 3, 4, 5, 6]
let set7 = new Set([...arr1, ...arr2])
console.log('distinct 2:', set7)
//1.向Set中添加元素。
let set1 = new Set()
set1.add(1)
set1.add(2)
set1.add(3)
console.log('added:', set1)
//3.判断某元素是否存在。
let set2 = new Set()
set2.add(1)
set2.add(2)
set2.add(3)
set2.delete(1)
console.log('has(1):', set2.has(1))
console.log('has(2):', set2.has(2))
//4.清除所有元素。
let set3 = new Set()
set3.add(1)
set3.add(2)
set3.add(3)
set3.clear()
console.log('cleared:', set3)
//数组去重
let arr=[1,111,33,11,11,11,34,5,6,7,4];
console.log( new Set([...arr]))
console.log([...arr])
</script>
</body>
</html>