forked from mrhm-dev/full-stack-army
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.js
More file actions
102 lines (83 loc) · 1.99 KB
/
object.js
File metadata and controls
102 lines (83 loc) · 1.99 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
90
91
92
93
94
95
96
97
98
99
100
101
102
// object literal
const microphone = {
brand: 'Fantech',
indicator: true,
price: 3400,
color: 'white',
// methods
startRecording() {
console.log('Recording started');
},
stopRecording() {
console.log('Recording stopped');
}
}
/**
* There are two different parts in object
* 1. Noun / Adjective (State/data/property/field)
* 2. Verb / (functionalities -> start, stop)
*/
microphone.startRecording()
microphone.stopRecording()
console.log(microphone);
console.log(Object);
// constructor function
const testObj = new Object()
testObj.name = 'Test Object'
testObj.time = new Date()
console.log(testObj);
console.log(testObj.time.getDate());
// object k freeze kore dey
// new property add korte dey na
Object.freeze(microphone)
microphone.newProperty = 'hi'
console.log(microphone);
// get key and value
console.log(Object.keys(microphone));
console.log(Object.values(microphone));
// [
// 'brand',
// 'indicator',
// 'price',
// 'color',
// 'startRecording',
// 'stopRecording'
// ]
// [
// 'Fantech',
// true,
// 3400,
// 'white',
// [Function: startRecording],
// [Function: stopRecording]
// ]
// concat function
console.log('micro'.concat('phone'));
console.log('micro' + 'phone');
// notation
// dot notation -> microphone.brand
// array notation -> microphone[k]
for(let k in microphone){
console.log(k, microphone[k]);
}
// brand Fantech
// indicator true
// price 3400
// color white
// startRecording [Function: startRecording]
// stopRecording [Function: stopRecording]
// check is a object is empty or not
const empty ={}
if(Object.keys(empty).length === 0){
console.log('This object is empty');
}
// object to key value pair
console.log(Object.entries(microphone));
const array = [
[ 'brand', 'Fantech' ],
[ 'indicator', true ],
[ 'price', 3400 ],
[ 'color', 'white' ]
]
console.log(Object.fromEntries(array));
// { brand: 'Fantech', indicator: true, price: 3400, color: 'white' }