forked from mouredev/hello-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-set.js
62 lines (38 loc) · 1012 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
62
/*
Clase 3 en vídeo | 24/07/2024
Condicionales, arrays y sets
https://www.youtube.com/live/XCNjoIoO3Ws?si=3XCjdZ9r41JID-by&t=978
*/
// 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)