Skip to content

Instantly share code, notes, and snippets.

@sehmbimanvir
Created March 18, 2022 17:14
Show Gist options
  • Save sehmbimanvir/3981e2c5f6177f2d4b1f25535d094fc0 to your computer and use it in GitHub Desktop.
Save sehmbimanvir/3981e2c5f6177f2d4b1f25535d094fc0 to your computer and use it in GitHub Desktop.
Javascript Deep Copy using Recursion
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