What is deep copy and shallow copy?
The concept of deep copy and shallow copy exists only on the object array and on the array obj .
Shallow copy is: Fuzzy replication, that is, whether the other side is a string type or reference type are copied all over. As a result, the contents of the two variables change simultaneously.
A deep copy is a purposeful copy that simply wants to copy the contents of a variable store.
Deep Copy method: letb = Json.parse (Json.strigify (a));
There are two types of JavaScript values : string Types and reference types
Copy of the string type, the value changes without affecting another variable, such as:
Let a=7; Let B=a; a=6;
Console.log (a)//a=6
Console.log (b)//b=7
Copy of a reference type that affects another variable when the value changes. Such as:
Let a={name: ' Xiaohong '}; Let B=a; A.name= ' Xiaowang;
Console.log (A.name)//a= ' Xiaowang '
Console.log (b.name)//b= ' Xiaowang '
Because arrays and objects store not the content itself, but the address of the content, the variable also points to the address when the array and object are copied to another variable.
When A.name changes only the content changes, the address does not change, so point to a at the same address. A.name and B.name have changed.
Deep copy and shallow copy of JS