Last active
October 24, 2018 02:38
-
-
Save nadavrt/8d429e8207392f704fb2c049f12e4ace to your computer and use it in GitHub Desktop.
A one-line JavaScript function that merges two objects.
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
/** | |
* Merge two objects. Warning: this function permanently changes obj1 due to it being passed by reference. | |
* If a property/method exists in both objects obj2's will overwrite the value that existed in obj1. | |
* @param obj1 The object to merge into. | |
* @param obj2 An object with properties to add to obj1. | |
* @return NULL | |
**/ | |
function mergeObjects(obj1, obj2) | |
{ | |
Object.keys(obj2).forEach(function(key) { obj1[key] = obj2[key]; }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment