I want to update this sorted result in javascript.
A1-1, A1-3, A1-3-1, A1-4, A2, A4-1, A6-3, A13-1, A13-2, A13-3, A13-11, A13-14, A51- 2
But I have the following result with this code.
sortedAlphabetListData.sort(
function(a,b){
if( a[0] < b[0] ) return -1;
if( a[0] > b[0] ) return 1;
return 0;
}
);
A1-1, A1-3, A1-3-1, A1-4, A13-1, A13-11, A13-14, A13-2, A13-3, A2, A4-1, A51-2, A6- 3
I tried this library.
https://gist.github.com/think49/660141
But this did not work. “A23” came first, and “A3-1” came after.
I read this post and tried it.
Javascript: natural looking alphanumeric strings
var collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
var sortedAlphabetListData = alphabetListData.sort(collator.compare);
But it only works on IE11 and does not work on Safari. I need to support IE9 and safari.
I need your help. Thank!