当前位置:网站首页>Native JS perfectly realizes deep copy
Native JS perfectly realizes deep copy
2022-07-25 23:40:00 【front-end technology】
Native JS Perfect deep copy
Don't talk much , Go straight to the code :
function deepClone(source) {
let targetObj = source.constructor == Array?[]:{
};
for(let keys in source) {
if(source.hasOwnProperty(keys)) {
if(source[keys] && typeof source[keys]=='object') {
targetObj[keys] = source[keys].constructor == Array?[]:{
};
targetObj[keys] = deepClone(source[keys]);
}else {
targetObj[keys] = source[keys];
}
}
}
return targetObj;
}
All right. , The code is very simple , If you have questions, you can leave a message below .
边栏推荐
猜你喜欢

XXE&XML-外部实体注入-利用和绕过

Release of v6.5.1/2/3 series of versions of Xingyun housekeeper: the ability of database OpenAPI continues to be strengthened

Docker installation redis-5.0.12 (remote access)

SAP Message No. VG202 IDoc E1EDK18 中付款条款已经转移:检查数据

Several commonly used traversal methods
![[Muduo] EventLoop event cycle](/img/80/824c7061d58796d454be0c438e257c.png)
[Muduo] EventLoop event cycle

chown: changing ownership of ‘/var/lib/mysql/‘: Operation not permitted

【代码案例】博客页面设计(附完整源码)

What is the difference between'1 and'b1 when assigning values

谷粒学苑P98踩坑 e.GlobalExceptionHandler : null
随机推荐
反射之类加载过程
POI special effects Market Research
[Muduo] package EventLoop and thread
Practical skills of easyexcel
【代码案例】博客页面设计(附完整源码)
【微信小程序】页面导航
XXE&XML-外部实体注入-利用和绕过
TS interface
Multimodal deep multi modal sets
JS regular expression content:
SAP Message No. VG202 IDoc E1EDK18 中付款条款已经转移:检查数据
图的遍历-DFS,BFS(代码详解)
Qt风格(QSS)应用之QProgressBar
[Muduo] EventLoop event cycle
Constructors and prototypes
Deep and shallow copies
E-commerce RPA, a magic weapon to promote easy entry
行云管家V6.5.1/2/3系列版本发布:数据库OpenAPI能力持续强化
Computed and watch listening properties
Serialize data type