Search code examples
javascriptvue.jsvuejs2v-for

Start range in v-for="n in 10" from zero


I want to start the range from 0 instead of 1 in v-for="n in 10" which results in 1 2 3 .... 10 Is there a way to do it in Vuejs?


Solution

  • You can use index (i) instead of value (n), it will start with 0:

    <div v-for="(n, i) in 10">{{ i }}</div>
    

    Output:

    0
    1
    2
    ...