我有一个对象totalData,我正在对其进行分解,以添加一个新的对象值.我知道我可以使用模板字符串(如下所示)定义新的对象属性,但如何使用模板字符串来获取对象值?下面的代码只是运行了一个错误,例如在[${currentMonth}
]后面写着"预期标识符".还有别的方法吗?
const newTotalData = {
...totalData,
[`${currentYear}`]: {
[`${currentMonth}`]: {
[`${currentWeek}`]: {
[`${currentDay}`]: {
completedTasks: totalData[`${currentYear}`].[`${currentMonth}`].[`${currentWeek}`].[`${currentDay}`].completedTasks + 1
}
},
},
},
};