forked from mouredev/hello-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11-set.js
More file actions
69 lines (45 loc) · 1.03 KB
/
11-set.js
File metadata and controls
69 lines (45 loc) · 1.03 KB
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
63
64
65
66
67
68
69
/*
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,
]);
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
console.log(mySet);