2👍
Use sort
and Boolean to number type coercion like so:
return this.contacts.sort(({ isPrimary: a }, { isPrimary: b }) => b - a);
This works by comparing the numeric representations of true
and false
, which are 1
and 0
respectively, and based upon the return value of sort
‘s callback, it returns a number which determines the place each item should be moved too.
- [Vuejs]-How to navigate to a different .html page in Vue.js
- [Vuejs]-Conditional template rendering with props in Vue3?
Source:stackexchange.com