-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjects2.js
64 lines (51 loc) · 1.54 KB
/
Objects2.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
let user = Object.create({
name: "Mandar",
age: 21,
email: "Amytgingyiulike@gmail.cos"
})
console.log(user); // Object.create will return a blank object everytime
// Creating object from maps
let myMap = new Map()
myMap.set("name", "Mandar")
myMap.set("age", 21)
myMap.set("email", "Amytgingyiulike@gmail.cos")
console.log(myMap);
let mapObj = Object.fromEntries(myMap) // Converting map into object
console.log(mapObj);
// Object functions
console.log(Object.values(mapObj));
console.log(Object.keys(mapObj));
console.log(Object.entries(mapObj));
// Copy object without reference
console.log();
let obj2 = {...mapObj}
console.log(mapObj);
console.log(obj2);
mapObj.name = "Parte"
console.log(mapObj); // Change of name is not reflected in obj2 object
console.log(obj2);
// Copy object without reference [Method 2]
console.log();
let obj3 = Object.assign({}, mapObj)
console.log(obj3);
console.log(mapObj);
mapObj.name = "Mandar"
console.log(mapObj); // Change of name is not reflected in obj2 object
console.log(obj3);
// Copy object without reference [Method 3]
console.log();
let obj4 = JSON.parse(JSON.stringify(mapObj))
console.log(obj4);
console.log(mapObj);
mapObj.name = "Parte"
console.log(mapObj); // Change of name is not reflected in obj2 object
console.log(obj4);
// Object.seal
console.log();
Object.seal(mapObj)
mapObj.email = "test"
console.log(mapObj);
delete mapObj.email // It cannot delete the element as Object is sealed
console.log(mapObj);
delete obj4.email // It will delete the element as Object is not sealed
console.log(obj4);