Say I have the following two objects:
var a = {
"abc": {
"111": {
name: "jon"
}
},
"xyz": {
"222": {
name: "bill"
}
}
}
var b = {
"xyz": {
"333": {
name: "mary"
}
}
}
I then want to create a new object to merge the two by the top level key name. So to get something like this:
var c = {
"abc": {
"111": {
name: "jon"
}
},
"xyz": {
"222": {
name: "bill"
},
"333": {
name: "mary"
}
}
}
I imagine it's probably something you do with .map(), .each(), or .reduce()?
Would jQuery be helpful in this case? if so how?
loadashthen you can expect already built function for such cases, but IMO there's no need of using a complete library where as you can do it just simple loops, If you're already using then it's fine, let me see if there's any such function available in jQueryextendandmergebut none of them can be used directly for such case, you need to loop through the keys and than merge them