Skip to content

Instantly share code, notes, and snippets.

@Jonarod
Created December 6, 2019 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jonarod/acc1df261692c5e1576ff480ea08ba40 to your computer and use it in GitHub Desktop.
Save Jonarod/acc1df261692c5e1576ff480ea08ba40 to your computer and use it in GitHub Desktop.
Fast & concise deep copy / deep clone / shallow copy in Javascript
var deepCopy = function (o) {
var t, x, key
t = Array.isArray(o) ? [] : {}
for (key in o) {
x = o[key]
t[key] = (typeof x === "object" && x !== null && !(x instanceof Date)) ? deepCopy(x) : x
}
return t
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment