-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday7.js
56 lines (49 loc) · 1.05 KB
/
day7.js
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
// Object Creation and objects
let book={
title:"Song of Ice and Fire",
author:"George R R Martin",
year: 2000
}
console.log(book)
console.log(book.year)
console.log(book["title"])
//Object Methods
book.getInfo=function(){
console.log(`${this.title} is written by ${this.author}`)
}
book.getInfo();
book.setYear=function(y){
this.year=y;
console.log(this)
}
book.setYear(1994)
//Nested Objects
let library={
name: "ABC",
books: [
{
title:"Song of Ice and Fire 1",
author:"George R R Martin",
year: 2003
},
{
title:"Song of Ice and Firen 2",
author:"George R R Martin",
year: 2037
},
{
title:"Song of Ice and Fire 3",
author:"George R R Martin",
year: 20033
}
]
}
console.log(library.name)
library.books.forEach((obj)=>{
console.log(obj.title)
})
//Object iteration
console.log(Object.keys(book))
console.log(Object.values(book))
for(key in book)
console.log(book[key])