Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 723
Pritam Bohra Avatar asked Aug 03 '17 07:08

Pritam Bohra


2 Answers

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 ... 
like image 119
dfsq Avatar answered Nov 07 '22 02:11

dfsq


You can also just subtract a value from your integer

<div v-for="n in 10">   {{ n - 1 }} </div> 

This way you can have numbers with a negative value

like image 36
Craig Peckett Avatar answered Nov 07 '22 03:11

Craig Peckett