[Vuejs]-Access next index object's value within a loop โ€“ Vue JS

3๐Ÿ‘

โœ…

Your problem is when you get to your last item in the array your dayIndex+1 object does not exist. It is undefined. What you need to do is in your template determine if your object is defined and go from there.

  <div v-for="(everyDay, dayIndex) in eachPost.values" v-bind:key="dayIndex">
   <template v-if="eachPost.values[dayIndex+1]">
      <div v-if="everyDay['Date'] !== eachPost.values[dayIndex+1].Date">
         THIS WORKS
      </div>
  </template>

 </div>

Here is a jsFiddle of my working example

๐Ÿ‘คTrevor V

Leave a comment