How do I get the result of the below sorting be Food to Eat then "FOOD 123".
Apparently, the 2nd lower 'o' should bring Food to Eat to the first item after sorting.
I'm surprised this question is not easy to find the answer by Google. This feat is not included in the javascript standard is also surprising me.
[
"FOOD 123",
"Food to Eat"
].sort((a,b)=>{
return a.localeCompare(b)
})
[
"FOOD 123",
"Food to Eat"
].sort()

It seems that String.prototype.localeCompare accepts options, that can be found here. sensitivity: 'case' should achieve what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With