sort characters in string alphabetically javascript code example
Example 1: javascript string array sort alphabetically
var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort((a, b) =>
a.localeCompare(b)//using String.prototype.localCompare()
);
Example 2: javascript compare and sort strings alphabetically
function sortString(str){
var arr = str.split('');
var sorted = arr.sort();
return sorted.join('');
}Copy