I have an array of objects with various properties. I am using the v-for method in vue.js to render them in a list.
However, I am facing issues trying to sort the objects based on a specific property. Currently, I am sorting them in ascending order using the following function:
evenNumbers: function () {
return this.numbers.sort(function (a, b) { return a - b });
}
This works well for a simple array like [22, 1, 2, 3, 4, 5], but it fails for objects containing properties such as name and age.
numbers2: [
{
name: 'Alan',
age: 72
},
{
name: 'Thomas',
age: 32
},
// More similar objects here...
]
}
I want to be able to sort these objects by age in ascending order and then render only the age property inside an li element.
You can view the code snippet here: https://jsfiddle.net/marektchas/jyznx475/2/