Consider the following object:
myObject{
name: '...',
label: '...',
menuSettings: {
rightAlignment: true,
colours: [...],
},
}
I want to change the value of rightAlignment to false without altering the rest of the object. I attempted to use myObject.find(...) but it didn't work as expected. Then I tried
Object.assign(this.myObject, {menuSettings: {rightAlignment: false}});
However, this approach did not access the property correctly. Is there a cleaner way to accomplish this?
Edit: I discovered that the array I was attempting to modify actually contained multiple objects. The solution that worked for me was iterating over each myObject in the array and checking if menuSettings existed (as it was an optional property that sometimes wasn't present).
If menuSettings existed, I would then:
this.myObject.menuSettings.rightAlignment = true;