当前位置:网站首页>ES6 uses recursion to implement deep copy
ES6 uses recursion to implement deep copy
2022-04-23 07:48:00 【Brother Bing】
// Use recursion to implement deep copy
let deepCopy = function(obj){
// Judge whether the deep copy is an array or an object , If it is an array, copy the array , Object, copy the object
let newObj = obj instanceof Array ? []: {
};
if (obj && typeof obj === 'object'){
for (let key in obj){
if (obj.hasOwnProperty(key)){
newObj[key] = (obj[key] && typeof obj[key] === 'object') ? deepCopy(obj[key]) : obj[key];
}
}
}
return newObj;
}
// quote
let arr = [...]
let newArr = deepCopy(arr);
版权声明
本文为[Brother Bing]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230625584855.html
边栏推荐
- js之DOM学习获取元素
- Nodejs (II) read files synchronously and asynchronously
- Unity 获取一个文件依赖的资源
- SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)
- [self motivation series] what really hinders you?
- js之自定义属性以及H5中如何判断自定义属性
- url转成对象
- 踩坑日记:Unable to process Jar entry [module-info.class]
- King glory - unity learning journey
- ABAP CDS VIEW WITH ASSOCIATION示例
猜你喜欢
随机推荐
Processing of common dependency module
Ogldev reading notes
异步的学习
SAP 导出Excel文件打开显示:“xxx“的文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?
系统与软件安全研究(一)
SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)
H5 local storage data sessionstorage, localstorage
学会使用搜索引擎
c#读取INI文件和向ini文件写入数据
利用Lambda表达式解决c#文件名排序问题(是100大还是11大的问题)
keytool: command not found
Hot change scheme and dynamic update strategy of mobile game
解决在docker中部署mysql8, 密码正确但无法登陆MySQL问题
NodeJS(一) 事件驱动编程
ABAP 7.4 SQL Window Expression
instanceof的实现原理
Use of command line parameter passing library argparse
10. Update operation
C reads the registry
Custom time format (yyyy-mm-dd HH: mm: SS week x)









