-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsets.html
More file actions
99 lines (72 loc) · 2.92 KB
/
Copy pathsets.html
File metadata and controls
99 lines (72 loc) · 2.92 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-wEmeIV1mKuiNpC+IOBjI7aAzPcEZeedi5yW5f2yOq55WWLwNGmvvx4Um1vskeMj0" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css">
<link rel="shortcut icon" href="favicon.png" type="image/png">
<title>Sets</title>
</head>
<body>
<div class="m-5 p-5">
<p>Create a set from an array:</p>
<p id="demo"></p><br>
<p>The add() method adds values to a Set:</p>
<p id="demo1"></p><br>
<p>JavaScript Sets - Output / Listing them on front page.</p>
<p id="demo2"></p><br>
<p>The has() method returns true if a set contains a spesific value:</p>
<p id="demo3"></p>
</div>
<script>
// Creation of Set
const letters = new Set(["a", "b", "c"]);
// Display set.size by (.size) method
document.getElementById("demo").innerHTML = "The set has " + letters.size + " values.";
// Displaying whole set in console
console.log("Printing New Set for the first time!");
for (let k of letters) {
console.log(k);
}
// Add Method used to add new elements in set
letters.add("d");
letters.add("e");
document.getElementById("demo1").innerHTML = "The set has " + letters.size + " values.";
console.log("");
console.log("Here we are printing Set after Added elements!");
for (let k of letters) {
console.log(k);
}
// List all Elements
let text = "";
for (const x of letters) {
text += x + " ";
}
document.getElementById("demo2").innerHTML = text;
// Does the Set contain "d"?
answer = letters.has("d");
document.getElementById("demo3").innerHTML = "The answer is " + answer;
// ForEach Method - Used for Printing
console.log("");
console.log("This is ForEach Method used for Printing!");
letters.forEach((num) => {
console.log(num);
})
// Data Fetching Asyncronous
async function namet() {
const response = await fetch ("https://jsonplaceholder.typicode.com/users");
const data = await response.json();
return data;
}
namet().then((data) => {
console.log(data);
})
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8"
crossorigin="anonymous"></script>
<script src="script.js"></script>
</body>
</html>