Object deep clone - Node.js Object

Node.js examples for Object:Object Operation

Description

Object deep clone

Demo Code


function deep_clone(obj) {
    if (obj instanceof Array)
        return obj.map(deep_clone);
    if (typeof obj == "object") {
        var ret = {};
        for (var i in obj) ret[i] = deep_clone(obj[i]);
        return ret;
    }//from  w  ww .j a va  2s .  c  om
    return obj;
};

Related Tutorials