Note: the object is stored as a reference address, and the object inside the object is also a reference address, and the value inside the object is primitive and does not require a deep copy.Copy the code

1. If the elements in the copied object have only values and no references, there will be no difference between the shallow copy and the deep copy. Both the original object will be copied and a new object will be created. 2, if the copy of the object element contains references (like a store list with another list, is another list of reference), it is different from the shallow and deep copy, although shallow copy a copy of the original object, but still keep reference, so in the new object references in the value of the modified, will change the original value of the object in the list, The new object is completely separate from the original object but not completely separate. Deep copy, on the other hand, creates a new reference to the original object, creating a new list and placing a reference to the new list, thus separating the new object from the original object completely.

Parse (), json.stringify ()&& json.parse (). This method can be used in many cases, but if the object contains undefined, it will be deleted.

2, function clone(obj){ let cpObj =typeof obj === 'object'? obj instanceof Array? []:{}:obj; if(obj&&typeof obj === 'object'){ for(let i in obj){ cpObj[i] = clone(obj[i]) } } return cpObjCopy the code

}