How can I sort the following array, in a custom order, based on the prop2
's last 3 letters that have to be in this order 'ABR', 'FDE', 'ZFR' and also in descending order 'ZFR', 'FDE', 'ARB' for another array.
Sample input:
const arr = [
{ prop1: 3, prop2: '3FDE' },
{ prop1: 4, prop2: '5ZFR' },
{ prop1: 5, prop2: '7ABR' }
]
Expected output:
const arr1 = [
{ prop1: 5, prop2: '7ABR' },
{ prop1: 3, prop2: '3FDE' },
{ prop1: 4, prop2: '5ZFR' }
]
and
const arr2 = [
{ prop1: 4, prop2: '5ZFR' },
{ prop1: 3, prop2: '3FDE' },
{ prop1: 5, prop2: '7ABR' }
]