I am working with an array called "names" that starts off empty
names: []
To add elements to this array using the unshift()
function, which adds elements to the beginning instead of the end, I do it like this:
names.unshift("Leonardo")
names.unshift("Victor")
names.unshift("Guilherme")
I will be using v-for to display the array elements on my page in a list format:
<ul>
<li v-for="name in names">
{{ name }}
</li>
</ul>
The output will appear as:
- Guilherme
- Victor
- Leonardo
Now, I want to list them along with their indexes, so I proceed with the following code:
<ul>
<li v-for="(name, i) in names">
{{ i }}: {{ name }}
</li>
</ul>
This will result in:
- 1: Guilherme
- 2: Victor
- 3: Leonardo
However, I would like to reverse the order of the indexes in the v-for loop. How can I achieve this?