My question is simple, I have 2 objects like this:
object1 = {
    content1: {}
}
object2 = {
    stuff: {},
    moreStuff: {}
}
And I want to add the content of object2 to content1 (which is inside of object1).
Like this:
object1 = {
    content1: {
        stuff: {},
        moreStuff: {}
    }
}
                This is very simple;
object1.content1 = object2
This will allow you to add an object inside another object.
 
With other examples you will get a substitution instead of adding.
e.g.
const obj1 = {
	innerObj:{
  	name:'Bob'
  },
  innerOBj2:{
  	color:'blue'
  }
}
const obj2 = {
	lastName:'Some',
  age:45
}
obj1.innerObj = Object.assign(obj1.innerObj,obj2);
console.log(obj1);
Now if you need something more advance, you should take a look to some functional programming framework like ramda, which will allow you to merge object. R.merge.
Something keeping you from doing: object1.content1 = object2 ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With