I have this object totalData which I am destructuring to add on a new object value. I understand I am able to define new object properties using template strings (as shown below) but how can I use template strings to get an objects value? The code below just runs an error saying "identifier expected" after the .[${currentMonth}
] for example. Is there another way of doing this?
const newTotalData = {
...totalData,
[`${currentYear}`]: {
[`${currentMonth}`]: {
[`${currentWeek}`]: {
[`${currentDay}`]: {
completedTasks: totalData[`${currentYear}`].[`${currentMonth}`].[`${currentWeek}`].[`${currentDay}`].completedTasks + 1
}
},
},
},
};