SOURCE

function deepCopy(obj) {
    const isObj = (object) => (typeof object === 'object' && object !== null) || Array.isArray(object);

    if (!isObj(obj)) {
        return;
    }

    let re = Array.isArray(obj) ? [] : {};

    for (let i in obj) {
        if (obj.hasOwnProperty(i)) {
            if (isObj(obj[i])) {
                re[i] = deepCopy(obj[i]);
            } else {
                re[i] = obj[i];
            }
        }
    }

    return re;
}


let obj = [1,2,3,4];
let deepObj = deepCopy(obj);
deepObj.push(5, 4,66);
deepObj.push(5);
console.log('aaaa', deepObj, obj);
console 命令行工具 X clear

                    
>
console