Given the following object
const data = {
"123-456": {
"03": 2,
"04": 0,
"05": 0,
"06": 0,
"07": 0,
"08": 1,
"09": 1
},
"123-789": {
"03": 2,
"04": 0,
"05": 0,
"06": 0,
"07": 0,
"08": 1,
"09": 1
}
};
And the following variables
const value = 10;
const weekday = "03";
const id = "123-456";
I need to create a copy of the data
object where the value of the id
and day of the given week changes. So given the previous parameters the new object would be the following.
{
"123-456": {
"03": 10, // <- here the new value
"04": 0,
"05": 0,
"06": 0,
"07": 0,
"08": 1,
"09": 1
},
"123-789": {
"03": 2,
"04": 0,
"05": 0,
"06": 0,
"07": 0,
"08": 1,
"09": 1
}
}
And tried to make a copy but without success
This is some of my tries
const newData = { ...data, [id]: { ...data[id], data[id][weekday]: value } };
Thanks for the help