-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeepCopyShallowCopy.js
More file actions
47 lines (36 loc) · 924 Bytes
/
Copy pathdeepCopyShallowCopy.js
File metadata and controls
47 lines (36 loc) · 924 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
43
44
45
46
47
// Objevct copy -------------------------
// In Object copy makes by refrence --------------
let obj = {
name:"shivani"
}
let copy = obj
copy.name = "aman"
console.log(obj ,"obj")
// Shallow copy ------------------
// In this its does not make the copy of memory allocation, Its makes the copy of value
let obj1 = {
name:"amisha"
}
let user = Object.assign({} , obj1)
// Destructuring is also a way of doing this -------------
// let user = {...obj1}
user.name ="durgesh"
console.log(user)
console.log('obj1' , obj1)
// Deep copy ----------------------
// Make a copy of value
let obj2 = {
name:"amisha" ,
data:{
role:"frontend"
},
work:function (){
return true
}
}
let users = JSON.parse(JSON.stringify(obj2))
// Destructuring is also a way of doing this -------------
// let user = {...obj1}
users.name ="durgesh"
console.log(users)
console.log('obj1' , obj2)