Created
March 18, 2022 17:14
-
-
Save sehmbimanvir/3981e2c5f6177f2d4b1f25535d094fc0 to your computer and use it in GitHub Desktop.
Javascript Deep Copy using Recursion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const deepCopy = data => { | |
if (typeof data !== "object" || !data) return data; | |
let result = Array.isArray(data) ? [] : {}; | |
for (let i in data) result[i] = deepCopy(data[i]); | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment