-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyobject.js
More file actions
64 lines (49 loc) · 1.3 KB
/
myobject.js
File metadata and controls
64 lines (49 loc) · 1.3 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
// object syntax
// First: Obect Contructor
const obj1 = new Object ({
name: 'Adegbite',
age: 26,
phone: '08032366804'
})
console.log(obj1.name + ' is ' + obj1.age + ' with ' + obj1.phone);
//Second: Object Literal
const obj2 = {
School: 'OGS',
State:'Osun'
}
console.log(obj1.name + ' went to ' + obj2.School + ' at the age of ' + obj1.age);
// How to add to object properties
obj2.city = 'Osogbo'
console.log(obj2.city);
// How to delete from Object properties
delete obj2.School
console.log(obj2.School);
// How to use square bracket
// For multiword properties like 'Last Name', 'Last-Name'
// You use it when you don't have standard/valid variable name.
obj2["First Name"] = 'Adekunle'
console.log(obj2["First Name"]);
// Property value Shorthand
function shotname(lg, region){
return {
lg:lg,
region:region,
}
}
let me = shotname('Olorunda', 'SW')
console.log(me.lg);
function shortname(lg1, region1) {
return {
lg1,
region1
}
}
let me1 = shortname('Osogbo','South West')
console.log(me1.region1);
// Existence check
// it provide a way to test whether the property exists.
// syntx: key in object
console.log('lg1' in me1);
for (let lg1 in me1) {
console.log(object);
}