Vue array object deep copy

Vue array object deep copy

Introduction:

1. In an array A, there are multiple objects in A, and A is copied to B, that is, B=A. At this time, if the value of the object in A is modified, B will be changed at the same time.
2. If you don't want this two-way binding in Vue, choose deep copy.
3. The idea of ​​deep copy is to use Object.assign(target, source) to generate a new copy object.

method call

function coppyArray(arr){
   return arr.map((e)=>{
        if(typeof e==='object'){
           return Object.assign({},e);
         }else{
           return e;
       }
     }) 
 }

Guess you like

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