Categories
Vue Answers

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

Spread the love

To reverse the order of an array using v-for and orderBy filter in Vue.js, we use the reverse method.

For instance, we write

<template>
  <ul>
    <li v-for="item in items.slice().reverse()">
      //do something with item ...
    </li>
  </ul>
</template>

to make a copy of the items array with slice.

And we call reverse to return a reversed version of the copied array.

We then use v-for to render the items in the reversed 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 *