I am trying to merge the following objects into one but having no luck so far - the structure is as follows in my console.log :
2018-05-11 : {posts: 2} // var posts
2018-05-11 : {notes: 1} // var notes
Once merged I want it to look like the following
2018-05-11 : {posts: 2, notes: 1}
I have tried object.assign() but it is just removing the initial posts data - what is the best approach for this?
Object.assign( a, b )if you want to add b to a.Object.assign( {}, a, b )if you want to add both a and b to a new object. Can you show theObject.assign()code you tried?keysare unique. It is easy to loop over it like this.2018-05-11 : {posts: 2}into javascript as an object similar to{'2018-05-11': {posts: 2}}. Attempting to merge two such objects then runs into the problem thatassignis a shallow copy.