SOURCE

function deepClone(obj) {
    let res = Array.isArray(obj)?[]:{}
    if(obj && typeof obj ==='object'){
        for(let key in obj){
            if(obj.hasOwnProperty(key)){
                if(typeof obj[key] === 'object')
                    res[key] = deepClone(obj[key])
                else
                    res[key] = obj[key]
            }
        }
    }
    return res
}

let a = [1, 2,[2,3,4], 3, 4],b = deepClone(a);

a[0] = 2;
a[2][2] = 5

console.log(a, b);

function* isTree(arr){
    if(Array.isArray(arr)){
        for(let i = 0;i<arr.length;i++){
            yield * isTree(arr[i])
        }
    }
    else
        yield arr
}
console.log([...isTree(a)])
console 命令行工具 X clear

                    
>
console