[Vuejs]-How to list options in an alphabetical order vuejs

0👍

This is more of a javascript problem than a vuejs problem. You would want to sort the array before displaying it.

after declaring the array you can run this sort snippet.

quiz.questions.sort((a, b) => a.text.localeCompare(b.text));
quiz.questions.forEach(({ responses }) => responses.sort((a, b) => a.text.localeCompare(b.text)));

What this does is to sort the outer “object” while using the key (text) in ascending order, once the outer object has been sorted, you loop through the responses array inside the object to sort each object using the key(text) in ascending order.

Leave a comment