How to sort an array in a unique order

后端 未结 4 2005
暗喜
暗喜 2021-01-28 10:03

Given an array:

var myList = [ \'Normal\', \'Urgent\', \'Alert\', \'Casual\', \'Follow up\' ];

I want to output this list in say, a dropdown. I

4条回答
  •  长发绾君心
    2021-01-28 10:54

    var myList = [ 'Normal', 'Urgent', 'Alert', 'Casual', 'Follow up' ];
    
    console.log(['Urgent', 'Alert', ...myList.filter(item => item !== 'Urgent' && item !== 'Alert').sort()]);

提交回复
热议问题