最简单 深克隆例子

50 阅读1分钟

深克隆例子

export const getCloneObj = (obj) => {
	let newobj = obj.constructor === Array ? [] : {};
		if (typeof obj !== 'object') {
			return;
		}
		for (let i in obj) {
			newobj[i] = typeof obj[i] === 'object' ? cloneObj(obj[i]) : obj[i];
		}
		return newobj
}