I am wanting to set a variable to change the number value to get the correct array item
Console.log this and i get what i need , but any attempts made to add a variable are not working
// This works
lastKickoffTime = m_nfl_schedule_ar.w_5.slice(-1).pop().kickoff
Attempts that have not worked
weekNum = "5";
lastKickoffTime = m_nfl_schedule_ar.['w_' weekNum].slice(-1).pop().kickoff
lastKickoffTime = m_nfl_schedule_ar.w_[weekNum].slice(-1).pop().kickoff
lastKickoffTime = m_nfl_schedule_ar.w_weekNum.slice(-1).pop().kickoff
lastKickoffTime = m_nfl_schedule_ar.w_ weekNum .slice(-1).pop().kickoff
lastKickoffTime = m_nfl_schedule_ar.w_' weekNum '.slice(-1).pop().kickoff
CodePudding user response:
lastKickoffTime = m_nfl_schedule_ar.['w_' weekNum].slice(-1).pop().kickoff
is almost right. should be:
lastKickoffTime = m_nfl_schedule_ar['w_' weekNum].slice(-1).pop().kickoff