-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects_in_js.js
More file actions
92 lines (71 loc) · 1.85 KB
/
Copy pathobjects_in_js.js
File metadata and controls
92 lines (71 loc) · 1.85 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
// objects mimic real life objects: it has objects n properties
let h = "h";
// objects literals notation
let user = {
name: "yasir",
age: 30,
blog: ["BLOG 1", "BLOG 2"],
login: function(){
console.log('user has logged in...');
},
logout: function(){
console.log('user has logged out...');
},
bloglog: function(){
console.log(this);
}
};
console.log(user);
// it can be acccessed using .prop or [] example
console.log(user.name);
console.log(user["name"]);
// it can also b changed
user.name = 'ahmad' //or
user['age'] = 25
console.log(user.name);
console.log(user["name"]);
//o d type u re dealing with
console.log(typeof(user))
user.login()
//this in javascript in windows
console.log(this)
//this in objects
user.bloglog()
// i can use this to check d in of ['a','b','c'] example
userblog = {
name: 'yasir',
blog: ['blog1','blog2','blog3','blog4','blog5'],
logblog: function(){
console.log(this.blog)
},
listblog: function(){
console.log('this user has this list of blog')
this.blog.forEach(
function(blog, index){
console.log(`${index} is ${blog}`)
}
)
},
// i can also declare a method without using function keyword e.g
showblog(){
console.log(this.blog);
}
}
userblog.logblog()
userblog.listblog()
/* so if i have 2 object
console.log()
- if i use this inside .log() its going to refer to windows
bcs d windows is child in console
user.blog()
if i use this inside .blog() its going to refer to properties inside user
bcs dey are d child in d user
try it with MAth Object
*/
console.log(Math.random(this))
// array of objects... with this i can also access each of the properties
const blog = [
{blog:'this is blog 1', likes: 10},
{blog:'this is blog 2', likes: 12},
{blog:'this is blog 3', likes: 5},
]