Answers for "how to make a deep copy in javascript"

4

clone javascript object

let clone = Object.assign({}, objToClone);
Posted by: Guest on February-19-2020
1

how to make a deep copy in javascript

JSON.parse(JSON.stringify(o))
Posted by: Guest on March-01-2020
1

deep copy javascript

function copy(arr1, arr2) {
	for (var i =0; i< arr1.length; i++) {
    	arr2[i] = arr1[i];
    }
}
copy(arr1, arr2)
Posted by: Guest on February-01-2021
0

deep copy js

//recursive deep copy of object
function dup(o) {
    // "string", number, boolean
    if(typeof(o) != "object") {
        return o;
    }
    
     // null
    if(!o) {
        return o; // null
    }
    
    var r = (o instanceof Array) ? [] : {};
    for(var i in o) {
        if(o.hasOwnProperty(i)) {
            r[i] = dup(o[i]);
        }
    }
    return r;
}
Posted by: Guest on September-08-2020

Code answers related to "how to make a deep copy in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language