There are two fairly clean ways of replacing values in JS objects and arrays that I can think of.
Option 1 - create a new Object
Let's assume that we have an object like the one you defined above.
let objAttrDay = {
"1":{
"sunday":false,
"recurrentSunday":false
},
"2":{
"sunday":true,
"recurrentSunday":false
},
"3":{
"sunday":true,
"recurrentSunday":false
}
};
we can change the value of "recurrentSunday" to true like this.
objAttrDay = {
...objAttrDay, // deconstruct all previous values from this object
"3": {
...objAttrDay["3"], // we could also just write `"sunday": true`
"recurrentSunday":true // change value to true
}
};
You'll find that the only change made to the objAttrDay Object is the value of objAttrDay["3"]["recurrentSunday"]
Option 2 - Change the value of a specific key in your existing Object
Alternatively, we can select only the value that we want to change, like so:
objAttrDay["3"]["recurrentSunday"] = true
The first option is useful if you would like to create a new object to store your values which is popular in reactjs and often necessary if the initial object is immutable. (Like state or props).
If, however, you don't need to create a new object, I would recommend the second method as it is short, succinct, and will likely save processing power.
Example of your if statement with the second option.
if(contSunday >= 3){
objAttrDay["3"]["recurrentSunday"] = true;
};
Hope this helped!