-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetAndWeakSet.js
More file actions
47 lines (31 loc) · 744 Bytes
/
SetAndWeakSet.js
File metadata and controls
47 lines (31 loc) · 744 Bytes
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
// Set & weakSet
function log(anything) {
return console.log(anything)
}
// Sets
// let myArray = [] // literal syntax
// let myArray = new Array() // constractor syntax
// let mySet = new Set()
// mySet.add(5).add('Bangladesh')
// mySet.delete('Bangladesh')
// log(mySet.has('Bangladesh'))
// mySet.clear()
// log(mySet.size)
// log(mySet)
// Array to Set
// let myArray = [1, 2, 3]
// let mySet = new Set(myArray)
// // let mySet = new Set('Bangladesh')
// for (let value of mySet) {
// log(value)
// }
// Set to Array
// let myArray = [1, 2, 3]
// let mySet = new Set(myArray)
// log([...mySet])
// log(Array.from(mySet))
// Set uses
let myArray = [1, 2, 3]
let mySet = new Set(myArray)
mySet.add(4).add(2)
log(mySet)