0

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
1
  • It would help much if you include the data of m_nfl_schedule_ar so we could reproduce this. Commented Sep 27, 2022 at 20:03

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

now why in the heck does it work without the dot , makes no sense to me , but thansk !
it's either "dot notation" or "bracket notation"
.slice(-1).pop() can be replaced by .at(-1).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.