Skip to content

Instantly share code, notes, and snippets.

@shinout
Created March 5, 2014 16:51
Show Gist options
  • Save shinout/9371224 to your computer and use it in GitHub Desktop.
Save shinout/9371224 to your computer and use it in GitHub Desktop.
minimal deep copy in JavaScript
function deepCopy(val) {
if (Array.isArray(val)) return val.map(deepCopy);
if (typeof val != "object" || val === null || val === undefined) return val;
var ret = {};
for (var attr in val) if (val.hasOwnProperty(attr)) ret[attr] = deepCopy(val[attr]);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment