I have the following array to sort.
const input = ["12 - Blue, Red, Orange, Purple",
"16 - White, Black, Yellow, Blue, Pink",
"14 - Yellow, Brown, Grey, Maroon, Green",
"20 - Red, Black, Yellow, Peach, Aqua",
"7 - White, Cream, Grey, Green, Magenta" ]
The aim is to sort rows in ascending order like 7th row, then 12th, 14th, 16th finally 20th. Here is what I tried but not working
const input = [
"12 - Blue, Red, Orange, Purple",
"16 - White, Black, Yellow, Blue, Pink",
"14 - Yellow, Brown, Grey, Maroon, Green",
"20 - Red, Black, Yellow, Peach, Aqua",
"7 - White, Cream, Grey, Green, Magenta"
]
var x = input.sort(function(a, b) {
return a[0] > b[0] ? 1 : -1;
});
console.log(x)
How to sort such a complex array in ascending order?