array sort for letters js code example
Example 1: javascript sort chars in string
const sort = str => str.split('').sort((a, b) => a.localeCompare(b)).join('');
// Example
sort('hello world'); // dehllloorw
Example 2: sort arrays according to first array js
itemsArray.sort(function(a, b){
return sortingArr.indexOf(a) - sortingArr.indexOf(b);
});