-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.copy.js
More file actions
38 lines (33 loc) · 786 Bytes
/
Copy pathobject.copy.js
File metadata and controls
38 lines (33 loc) · 786 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
//? object copy
const print =(values)=>{
console.log(values)
};
const student1={
name:"Sandeep",
college:"KEC",
isGraduated:false,
image:null,
address:{
permanent:"x",
temporary:"y",
}
}
//?print(student1)
//? shallow copy
// const student2=student1;
// console.log(student2)
// student2.name="Kalyan";
// console.log(student1)
// console.log(student2)
//? we havenot changed anything in student2 still it shows change
//?spread operator(...)
// const student2={...student1};
// student2.name="suyasha"
// console.log(student2);
//? but in case of nested object it wont work it changes
//? deep copy
// structured clone
const student2=structuredClone(student1);
student2.address.permanent="z"
console.log(student1)
console.log(student2)