A
A
Aleksandr_KH2019-07-04 13:55:22
Vue.js
Aleksandr_KH, 2019-07-04 13:55:22

How to sort an array alphabetically VUE?

Hello.
Can you please tell me how to sort the array alphabetically by clicking on the button?
Klats

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-07-04
@Aleksandr_KH

computed property to do of course :

computed: {
  sortedUsers() {
    return [...this.users].sort((a, b) => a.name.localeCompare(b.name));
  },
},

A
Alexander, 2019-07-05
@metis

['foo', 'bar', 'anything'].sort((a, b) => (a > b ? 1 : -1));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question