Sometimes, we want to reverse the order of an array using v-for and orderBy filter in Vue.js.
In this article, we’ll look at how to reverse the order of an array using v-for and orderBy filter in Vue.js.
How to reverse the order of an array using v-for and orderBy filter in Vue.js?
The order of an array using v-for and orderBy filter in Vue.js, we can call the reverse
method on the array.
For instance, we write
<template>
<div>
...
<li v-for="item in items.slice().reverse()">...</li>
...
</div>
</template>
to make a copy of the items
array with slice
and then call reverse
to reverse the cloned array.
And then we use v-for
to render the items in the reversed array.
Conclusion
The order of an array using v-for and orderBy filter in Vue.js, we can call the reverse
method on the array.