sort letter javascript 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: string sort javascript
var names = ["Peter", "Emma", "Jack", "Mia"];
var sorted = names.sort(); // ["Emma", "Jack", "Mia", "Peter"]