因此,当数据进入时,它会被过滤到某一天。例如:
data.Item.Tuesday
但是我希望能够将“Tuesday”替换为在其他地方声明的变量。我似乎无法找出这种过滤方法实际上是什么。任何建议都非常感谢!
getWeekData(UserId, weekNumber).then((data) => {
if (!data.Item || !data.Item.weekTotal) {
console.log("Week Data Not Found");
} else {
weekExercise = data.Item.weekTotal;
dayTotal = data.Item.Monday;
yesterdayTotal = data.Item.Tuesday;
console.log("Week Total is: " + weekExercise);
console.log("Todays Total is: " + dayTotal);
console.log("Yesterdays Total was: " + yesterdayTotal);
}
});
答案 0 :(得分:1)
您可以像调用数组一样调用对象来替换tuesday
:
const day_variable = 'tuesday'
data.Item[day_variable]