Skip to content

Instantly share code, notes, and snippets.

@kanakiyajay
Last active August 29, 2015 14:05
Show Gist options
  • Save kanakiyajay/f36cba0d75482bc0abdf to your computer and use it in GitHub Desktop.
Save kanakiyajay/f36cba0d75482bc0abdf to your computer and use it in GitHub Desktop.
Cloning an object with multiple nested functions or keys using javascript
function cloneObject(obj) {
var clone = {};
for(var i in obj) {
if(typeof(obj[i])=="object" && obj[i] != null)
clone[i] = cloneObject(obj[i]);
else
clone[i] = obj[i];
}
return clone;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment