has been trying to find a fast and reliable way for JavaScript to deep-Copy the object, yesterday, a whim, push the object into an empty array, and then change the array through concat () or slice ()
Copy, and then take out the first element of the array to copy to the variable, is this variable a deep copy of the object? Just do what you say, on the code.
var a = { b: { 1 } }; var arr = []; Arr.push (a); var x = arr.slice (0); arr[0].b =N; Console.log (x[0].b);
If successful, the console is the object {c:1}, otherwise it is 12.
Failed, it seems that the array of concat, slice () and other methods do not make a deep copy of the original array, the inner element is still a heap address reference.
To make a deep copy of an object, or to use the Extend method of jquery, use JSON, although JSON can be problematic, refer to this article.
About deep-copy issues in JavaScript