Created
November 19, 2013 00:03
-
-
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
This file contains hidden or 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
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