forked from mouredev/hello-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-set.js
61 lines (37 loc) · 946 Bytes
/
11-set.js
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
51
52
53
54
55
56
57
58
59
60
61
/*
Clase 26 - Sets
Vídeo: https://youtu.be/1glVfFxj8a4?t=9952
*/
// Set
// Declaración
let mySet = new Set()
console.log(mySet)
// Inicialización
mySet = new Set(["Brais", "Moure", "mouredev", 37, true, "[email protected]"])
console.log(mySet)
// Métodos comunes
// add y delete
mySet.add("https://moure.dev")
console.log(mySet)
mySet.delete("https://moure.dev")
console.log(mySet)
console.log(mySet.delete("Brais"))
console.log(mySet.delete(4))
console.log(mySet)
// has
console.log(mySet.has("Moure"))
console.log(mySet.has("Brais"))
// size
console.log(mySet.size)
// Convertir un set a array
let myArray = Array.from(mySet)
console.log(myArray)
// Convertir un array a set
mySet = new Set(myArray)
console.log(mySet)
// No admite duplicados
mySet.add("[email protected]")
mySet.add("[email protected]")
mySet.add("[email protected]")
mySet.add("[email protected]")
console.log(mySet)