Answers for "javascript deep copy of object"

4

clone javascript object

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

how to deep copy an object in javascript

const obj1 = { a: 1, b: 2, c: 3 };
// this converts the object to string so there will be no reference from 
// this first object
const s = JSON.stringify(obj1);

const obj2 = JSON.parse(s);
Posted by: Guest on September-12-2020
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 "javascript deep copy of object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language