当前位置:网站首页>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;
}
边栏推荐
- Working principle of asemi three-phase rectifier bridge
- Personalized Federated Learning with Moreau Envelopes
- Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').
- Penetration test - directory traversal vulnerability
- Mobile number regular expression input box loses focus verification
- Codeforces Round #802 (Div. 2) C D
- Detailed summary of position positioning
- Detailed summary of float
- Difference between asemi high power FET and triode
- 2021-04-02
猜你喜欢

My IC journey - the growth of senior chip design verification engineers - "Hu" said that IC engineers are perfect and advanced

小白一键重装官网下载使用方法

Customize the console plot result style

olap分析引擎——Kylin4.0

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

Kotlin compose perfect todo project surface rendering background and shadow

Detailed summary of position positioning

ASEMI三相整流桥的工作原理

Virtual honeypot Honeyd installation and deployment

Vscade setting clang format
随机推荐
JS, BOM, DOM (VI)
ORA-00800: soft external error
EL & JSTL (XIII)
Google Earth engine (GEE) - Global jrc/gsw1_ 1 / batch download of yearlyhistory dataset (China region)
The SQL response is slow. What are your troubleshooting ideas?
Small sample learning data set
Codeforces Round #802 (Div. 2) C D
[keil] GPIO output macro definition of aducm4050 official library
DMA double buffer mode of stm32
DOM document object model (I)
Click to jump out and drag the pop-up window
Creation and use of MySQL index
2021-04-02
PHP uses JWT
Ranorex Studio 10.1 Crack
[image fusion] image fusion based on MATLAB directional discrete cosine transform and principal component analysis [including Matlab source code 1907]
Leader: who can use redis expired monitoring to close orders and get out of here!
融合CDN,为客户打造极致服务体验!
Even if you are not good at anything, you are growing a little bit [to your 2021 summary]
Bind simulation, key points of interpreting bind handwritten code [details]