Created
December 6, 2019 01:09
-
-
Save Jonarod/acc1df261692c5e1576ff480ea08ba40 to your computer and use it in GitHub Desktop.
Fast & concise deep copy / deep clone / shallow copy in Javascript
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
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