Snippets Collections
function deepCopy(obj){
    let toString = Object.prototype.toString;
    if(typeof obj !== 'object') return obj;
    if(obj === null) return null;
    if(Array.isArray(obj)) return;
    let newObj = {};
    for(let key in obj){
        if([key])==='[object Date]'){
            newObj[key] = new Date(obj[key])
        } else if([key])==='[object RegExp]'){
            newObj[key] = new RegExp(obj[key])
            newObj[key] = deepCopy(obj[key]);
    return newObj;

Sun Jun 19 2022 04:40:24 GMT+0000 (Coordinated Universal Time)

#javascript #object #deep #copy #clone #recursion

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension