Skip to content

Instantly share code, notes, and snippets.

@rodrigograca31
Last active August 12, 2020 11:46
Show Gist options
  • Save rodrigograca31/0e94078b80b016d0db37d1195a03755c to your computer and use it in GitHub Desktop.
Save rodrigograca31/0e94078b80b016d0db37d1195a03755c to your computer and use it in GitHub Desktop.
Deep copy objects in Javascript
/**
* Makes a copy of values not references and goes down the attributes
*/
deepCopy(o) {
var copy = o,
k;
if (o && typeof o === "object") {
copy =
Object.prototype.toString.call(o) === "[object Array]"
? []
: {};
for (k in o) {
copy[k] = this.deepCopy(o[k]);
}
}
return copy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment