/**
* 深度复制对象
* @param obj
* @returns
*/
export const deepClone = function (obj: any): any {
const otype = Object.prototype.toString.call(obj);
let target = obj;
if (otype === '[object Array]') {
target = []
for (let i = 0; i < obj.length; i++) {
target.push(deepClone(obj[i]));
}
} else if (otype === '[object Object]') {
target = {};
for (let key in obj) {
target[key] = deepClone(obj[key]);
}
}
return target;
}
前端深度复制对象、深拷贝
最新推荐文章于 2024-09-29 11:29:55 发布