-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor-in.html
42 lines (34 loc) · 1.27 KB
/
for-in.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>For In</title>
</head>
<body>
<script>
/*
## For In
● For In merupakan perulangan for yang digunakan untuk mengiterasi seluruh data property di object atau index di array
● Walaupun for in bisa digunakan untuk Array, namun tidak direkomendasikan untuk Array, karena biasanya kita jarang sekali butuh data index untuk Array, kita bisa menggunakan For Of (yang dibahas setelah ini)
*/
// Kode: For In di Object
const person = {
firstName: "Fauzan",
middleName: "Ahmad",
lastName: "M",
};
document.writeln(`<p>=====For In di Object=====</p>`);
for (const property in person) {
document.writeln(`<p>Property ${property} : ${person[property]}</p>`);
}
// Kode : For In di Array
document.writeln(`<p>=====For In di Array=====</p>`);
const names = ["Fauzan", "Tato", "Yono"];
for (const index in names) {
document.writeln(`<p>Index ${index} : ${names[index]}</p>`);
}
</script>
</body>
</html>