当前位置:网站首页>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
边栏推荐
猜你喜欢

Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight

MySQL8.0 安装/卸载 教程【Window10版】

int a = 1存放在哪

js之排他思想及案例

Authorization server (simple construction of authorization server)

Django uses MySQL database to solve error reporting

FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning

SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)

js之预解析

基于NLP的软件安全研究(二)
随机推荐
命令行参数传递库argparse的使用
Daily question | fear dominated by reverse linked list
层次输出二叉树
MySQL storage engine
Django uses MySQL database to solve error reporting
Unity ugui determines the solution of clicking on the UI and 3D objects
ABAP 实现发布RESTful服务供外部调用示例
移动Web(字体图标、平面转换、颜色渐变)
反转链表练习
异步的学习
BTREE, B + tree and hash index
Authorization+Token+JWT
SVG中Path Data数据简化及文件夹所有文件批量导出为图片
js案例之求最大值,反转数组,冒泡排序
Nodejs (I) event driven programming
MySQL isolation level
Configure NPM
Shapley Explanation Networks
Redis connection error err auth < password > called without any password configured for the default user
js之作用域、作用域链、全局变量和局部变量