-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15_objectsProperties.js
234 lines (123 loc) · 3.98 KB
/
15_objectsProperties.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// In JavaScript, objects are king. If you understand objects, you understand JavaScript.
// 1]Accessing JavaScript object Properties
// const myDreamHouse = {
// location: "village(Dewareda)",
// "design": "farmhouse tranditional",
// "budget": "20 lakhs",
// "is In The Construction Proces": false,
// specialitiesOfTheHouse: function () {
// return (`As this is my dream house, I am gonna customize it to the next level. This house will be located at ${this.location} and its design will be ${this.design} `)
// }
// }
// console.log(myDreamHouse. )
// console.log(myDreamHouse["is In The Construction Proces"])
// const x = "specialitiesOfTheHouse"
// console.log(myDreamHouse[x]())
// 2] JavaScript object for...in Loop
// const myDreamHouse = {
// location: "village(Dewareda)",
// "design": "farmhouse tranditional",
// "budget": "20 lakhs",
// "is In The Construction Proces": false,
// specialitiesOfTheHouse: function () {
// return (`As this is my dream house, I am gonna customize it to the next level. This house will be located at ${this.location} and its design will be ${this.design} `)
// }
// }
// for (let x in myDreamHouse) {
// console.log(myDreamHouse[x])
// }
//3] Adding New Properties
// const myDreamHouse = {
// location: "village(Dewareda)",
// "design": "farmhouse tranditional",
// "budget": "20 lakhs",
// "is In The Construction Proces": false,
// specialitiesOfTheHouse: function () {
// return (`As this is my dream house, I am gonna customize it to the next level. This house will be located at ${this.location} and its design will be ${this.design} `)
// }
// }
// myDreamHouse.interior = "chandan-wood"
// console.log(myDreamHouse);
//4] Deleting Properties
// const myDreamHouse = {
// location: "village(Dewareda)",
// "design": "farmhouse tranditional",
// "budget": "20 lakhs",
// "is In The Construction Proces": false,
// specialitiesOfTheHouse: function () {
// return (`As this is my dream house, I am gonna customize it to the next level. This house will be located at ${this.location} and its design will be ${this.design} `)
// }
// }
// // delete myDreamHouse["is In The Construction Proces"]
// delete myDreamHouse.location
// console.log(myDreamHouse);
//5] Nested Objects
// const myObj = {
// name: "yadnyesh",
// rollNO: 36,
// class: 3,
// myCarCollection: {
// car1: "XUV700",
// car2: "Thar",
// car3: "Rolls-Royals",
// myFavCars: {
// car1: "dodge challanger",
// car2: "Elentra",
// car3: "Lamborgini",
// favCarColors: ["black", "yellow", "purple"],
// mostFavCarEver: {
// car1:"formula 1"
// }
// }
// }
// }
// // console.log(myObj.myCarCollection.myFavCars.favCarColors[1])
// console.log(myObj["myCarCollection"]["myFavCars"]["favCarColors"][0]);
//6] Object inside an array
// const arr = [
// {
// name: "yadnyesh",
// rollNO: 43,
// class:1
// },
// {
// name: "suyash",
// rollNO: 22,
// class:2
// },
// {
// name: "vaibhav",
// rollNO: 13,
// class:3
// },
// ]
// console.log(arr[2])
// const newArr=[1,2,3,4,5]
//7]Object.assign()
// const obj1 = {
// name: "pranav",
// rollNo: 33,
// class:2
// }
// const obj2 = {
// name1: "vihas",
// rollNo1: 21,
// class1:2
// }
//spread operator
// const obj3 = { ...obj1, ...obj2 }
// console.log(obj3);
//8]Object.keys()
const myDreamHouse = {
"location": "village(Dewareda)",
"design": "farmhouse tranditional",
"budget": "20 lakhs",
"is In The Construction Proces": false,
specialitiesOfTheHouse: function () {
return (`As this is my dream house, I am gonna customize it to the next level. This house will be located at ${this.location} and its design will be ${this.design} `)
}
}
//10]Object.entries()
// console.log(Object.entries(myDreamHouse));
// 11]obj.hasOwnProperty
console.log(myDreamHouse.hasOwnProperty("budfssaget"))