We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5690f83 commit c9926b9Copy full SHA for c9926b9
challenges/objects-challenges.md
@@ -90,6 +90,25 @@ const x = { ...obj};
90
const x = JSON.parse(JSON.stringify(obj));
91
```
92
93
+```js
94
+function deepCopy(obj){
95
+ if(!obj) return obj;
96
+ const copyObj = {};
97
+ for(const key in obj){
98
+ let val;
99
+ if(obj[key] !== 'object')
100
+ nVal[key] = obj[key];
101
+ else
102
+ copyObj[key] = deepCopy(obj[key]);
103
+
104
+ copyObj[key] = val;
105
+ }
106
+ return copyObj;
107
+}
108
109
+const x = deepCopy(obj);
110
+```
111
112
###### Notes
113
3rd solution provided does deep copy of a nested object also but this technique results in loss of data
114
0 commit comments