We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5690f83 + 7470749 commit 34ae88fCopy full SHA for 34ae88f
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(typeof obj[key] !== 'object')
100
+ val = obj[key];
101
+ else
102
+ val = 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