-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathobjects.js
More file actions
42 lines (30 loc) · 905 Bytes
/
objects.js
File metadata and controls
42 lines (30 loc) · 905 Bytes
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
let input = 'name'
let employee = {
name: 'Sayantan',
tech: 'JS',
'work exp': 0 //BAD PRACTICE...WE SHOULD USE "_" INSTEAD OF SPACE
}
console.log(employee.name);
console.log(employee.tech);
console.log(employee['work exp']);
console.log(employee[input]);
let programmer = {
name : 'Sayantan',
skills : 'js, python',
laptop : {
cpu : 'r7',
ram : '8gb',
gpu : 'RTX 3050',
brand : {
mainBrand : 'Lenovov',
subBrand : 'Legion'
}
}
}
console.log(programmer.laptop.brand.subBrand.length)
delete programmer.laptop.brand.subBrand
console.log(programmer.laptop.brand.subBrand?.length) // WE CAN PUT "?" IF WE ARE NOT SURE THE PROPERTY IS PRESENT IN THE OBJECT OR NOT
for(let key in programmer.laptop){
console.log(key, programmer.laptop[key])
}
console.log(programmer["name"].toString());