Categories
Vue Answers

How to reverse the order of an array using v-for and orderBy filter in Vue.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *