Top
Fork me on Gitee

js 深拷贝

数组对象的深拷贝

function copydeep(obj) {
      var newobj = obj.constructor === Array ? [] : {};
      if (typeof obj !== 'object') {
        return;
      }
      for (var i in obj) {
        newobj[i] = typeof obj[i] === 'object' ? copydeep(obj[i]) : obj[i];
      }
      return newobj
}
posted @ 2020-07-23 12:22  lisashare  阅读(80)  评论(0编辑  收藏  举报