--兵器谱--深拷贝的递归实现--

深拷贝的实现

function deepCopy(data) {
    let obj;
    if (Array.isArray(data)) {
        obj = [];
        for (let i = 0 ; i < data.length ; i ++) {
            obj.push(deepCopy(data[i]));
        }
    } else if (typeof data == "object") {
        obj = {};
        for (let keys in data) {
            obj[keys] = deepCopy(data[keys]);
        }
    } else {
        obj = data;
    }
    return obj;
}
posted @ 2021-03-24 17:42  小虾米在code江湖  阅读(35)  评论(0编辑  收藏  举报