Created
November 24, 2015 11:25
-
-
Save Colorfulstan/a330cb2f86ea230b3ddf to your computer and use it in GitHub Desktop.
From http://stackoverflow.com/questions/21450060/how-to-join-two-json-object-in-javascript-without-using-jquery Merging 2 JSON Objects with hierarchie
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
var _mergeRecursive = function(obj1, obj2) { | |
//iterate over all the properties in the object which is being consumed | |
for (var p in obj2) { | |
// Property in destination object set; update its value. | |
if ( obj2.hasOwnProperty(p) && typeof obj1[p] !== "undefined" ) { | |
_mergeRecursive(obj1[p], obj2[p]); | |
} else { | |
//We don't have that level in the heirarchy so add it | |
obj1[p] = obj2[p]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment