当前位置:网站首页>JS handwriting depth clone array and object
JS handwriting depth clone array and object
2022-06-25 05:05:00 【I am Feng Feng Yi】
function deepClone(obj) {
if (typeof obj !== 'object') {
return obj;
}
if (Array.isArray(obj)) {
return deepCloneArray(obj);
} else {
return deepCloneObject(obj);
}
}
function deepCloneArray(arr) {
const target = [];
arr.forEach(it => {
if (typeof it === 'object') {
target.push(deepClone(it));
} else {
target.push(it);
}
})
return target;
}
function deepCloneObject(obj) {
const target = {
};
for (const prop in obj) {
if (Object.hasOwnProperty.call(obj, prop)) {
if (typeof obj[prop] === 'object') {
target[prop] = deepClone(obj[prop]);
} else {
target[prop] = obj[prop];
}
}
}
return target;
}
边栏推荐
猜你喜欢

Summary of SQL injection (I)

Detailed summary of float

What if the desktop computer is not connected to WiFi

Rce code execution & command execution (V)

固态硬盘开盘数据恢复的方法

CTFHub-rce

The construction and usage of wampserver framework

What if win11 Bluetooth fails to connect? Solution of win11 Bluetooth unable to connect

基于SSH实现的学生成绩管理系统

IronOCR 2022.1 Crack
随机推荐
DMA double buffer mode of stm32
How to make colleagues under the same LAN connect to their own MySQL database
MySQL concept and operation (III)
Heavy broadcast | phase shift method + mathematical principle derivation of multi frequency heterodyne + implementation
Customize the console plot result style
The construction and usage of wampserver framework
Mysql interactive_ Timeout and wait_ Timeout differences
Compatible with Internet Explorer
融合CDN,为客户打造极致服务体验!
Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').
2021-10-24
The print area becomes smaller after epplus copies the template
Activereportsjs V3.0 comes on stage
Google Earth Engine(GEE)——全球JRC/GSW1_1/YearlyHistory数据集的批量下载(中国区域)
ThinkPHP 5 log management
great! Auto like, I use pyautogui!
Use serialize in egg to read and write split tables
Kotlin compose listens to the soft keyboard and clicks enter to submit the event
Kotlin compose perfect todo project surface rendering background and shadow
CTFHub-rce