In this tutorial, you’ll learn how to sort an array by a property value in Vue.js.
Let’s start by creating an array of objects:
It is a simple todo list. Each task consists of a title and status.
Suppose you want to sort this array by one of its properties. You can do this by using the
sort() method of an
Hi, I'm Renat 👋
sort() method takes 2 parameters (a, b) and compares them.
Let’s sort our array by title in descending order:
todos.sort((a, b) => (a.title > b.title) ? 1 : -1)
The output will be:
If you find this post useful, please let me know in the comments below and subscribe to my newsletter.
Want to share this with your friends?
Incoming search terms: