Given an array:
var myList = [ \'Normal\', \'Urgent\', \'Alert\', \'Casual\', \'Follow up\' ];
I want to output this list in say, a dropdown. I
You could use an object for the sort order.
var array = [ 'Normal', 'Urgent', 'Alert', 'Casual', 'Follow up' ]; array.sort(function (a, b) { var order = { Urgent: -2, Alert: -1 }; return (order[a] || 0) - (order[b] || 0) || a.localeCompare(b); }); console.log(array);