shallow copy deep copy

Assign the value of a variable to another variable. If it is a reference type, there are two ways: shallow copy and deep copy
  
 Shallow copy refers to newObj, that is, copying the pointer, that is, passing by reference, it will change itself
 
A deep copy creates a new object with the same content as the original object that needs to be copied. Similar to pass-by-value (pass-by-value refers to basic data types) itself does not change
Three ways of deep copy
The first is to use the mechanism of map to return a new array return userlist.map(item=>item);
Second, use the mechanism of Array.from to return a new array return Array.from(userlist);
The third one, use... to unwrap the array. Put on a new array by yourself return [...userlist];

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325112593&siteId=291194637