Created
December 21, 2014 11:37
-
-
Save bultas/5ce80f26454f8f7d3df9 to your computer and use it in GitHub Desktop.
Merge Objects (Recursively)
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
/** | |
* Merge objects (recursively merge deep objects) | |
* @param {object} objects as arguments to merge merge(object, object2,..) | |
*/ | |
var merge = function() { | |
var res = {}; | |
for (var i = 0; i < arguments.length; ++i) { | |
if (arguments[i]) { | |
for (var prop in arguments[i]) { | |
if (typeof arguments[i][prop] === "object") { | |
res[prop] = merge(res[prop], arguments[i][prop]); | |
} else { | |
res[prop] = arguments[i][prop]; | |
} | |
} | |
} | |
} | |
return res; | |
}; | |
module.exports = merge; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment