1

I need to access the index variable of a nested v-for loop. Can this be done? My code is

<div v-for="(dayDataArray, key, index) in props_league_data_nfl">
     <div v-for="(arrayItem, key, arrayItemIndex) in dayDataArray" class="col-xs-12 col-sm-4 col-lg-3">



    <!-- some code here -->

<div> {{ props_box_game_scores_nfl[nfl_days[index].split(' ')[0].toLowerCase()][arrayItemIndex] }} </div>`

If I set it up like above with separate names for indexes then arrayItemIndex seems to be ignored. If I use index for both for loops then I get an exception in the nfl_days[index] reference. How can you access the second index variable? It seems like the index name has to be used in both instances? Any suggestions or workarounds appreciated...

2
  • Is dayDataArray an object or an array? Commented Oct 2, 2019 at 18:11
  • dayDataArray is an array. Commented Oct 2, 2019 at 18:13

1 Answer 1

1

For an array v-for only has two arguments, not three. So it should be:

v-for="(arrayItem, arrayItemIndex) in dayDataArray"

It only has 3 arguments when iterating over an object.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. My bad. I should have rtfm rather then copying from previous line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.