Skip to content

Instantly share code, notes, and snippets.

@nicksheffield
Created November 19, 2013 00:03
Show Gist options
  • Save nicksheffield/7537650 to your computer and use it in GitHub Desktop.
Save nicksheffield/7537650 to your computer and use it in GitHub Desktop.
Recursively merge two objects. Original objects will be overwritten by the ones from updates
function merge(original, updates){
for(var key in updates){
if(updates[key] instanceof Object && !(updates[key] instanceof Array)){
if(!original[key]) original[key] = {};
original[key] = merge (original[key], updates[key]);
}else{
original[key] = updates[key];
}
}
return original;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment