-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathObject.html
66 lines (52 loc) · 1.7 KB
/
Object.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!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>Learn Object</title>
</head>
<body>
<script>
// create a object
let thisObject = {
"name": "adriana",
age: 19
};
// Addication / Menambahkan Object
thisObject["name"] = "Adrian";
thisObject["address"] = "Jl.sini";
thisObject["city"] = "Situ";
//delete object
delete thisObject["city"];
console.table(thisObject);
console.info(`Name: ${thisObject.name}`);
// In Oparator , mengecek sebuah property di object (bukan value) apakah ada atau tidak
if ("name" in thisObject) { // true
alert(`Hello ${thisObject.name}`)
} else {
alert('Property not Found');
}
// Optional Chaining, ppengecekan pada sebuah propery, apakah property tersebut undigined/null atau tidak
const person = {
address: {
country: "Indonesia"
}
};
// var = varObject?.property1?.property2
let country = person?.address?.country;
document.writeln(`<h1>${country}</h1>`);
// with statment, Tidak di rekomendasikan
const thisWith = {
firstName: "Adrian",
middleName: "Miftahul",
lastName: "Haq",
}
with (thisWith) { //Berguna agar tidak perlu lagi memanggil nama object sama lagi
console.info(firstName);
console.info(middleName);
console.info(lastName);
}
</script>
</body>
</html>