Vue - check if you are on the last prop of a v-for loop Vue - check if you are on the last prop of a v-for loop vue.js vue.js

Vue - check if you are on the last prop of a v-for loop


Here is one way.

<span v-for="(val,key,index) of person">  key: {{key}}, val: {{val}}, index: {{index}}  <span v-if="index != Object.keys(person).length - 1">, </span></span>


Works Great

<div id="app">  <div v-for="(item, index) in items">    <div v-if="index == items.length - 1">yes</div>    {{ item }}, {{ index }}  </div></div>


You can also "cheat" by inserting the comma before each item, as it's easier to check for the first item (key !== 0).

<span v-for="(val, key) in person">  <span v-if="key !== 0">, </span>  {{key}}: {{val}}</span>