JavaScript: Convert the letters of a given string in alphabetical order
JavaScript Basic: Exercise-52 with Solution
Sort Letters Alphabetically in String
Write a JavaScript program to convert letters of a given string alphabetically.
This JavaScript program takes a string and sorts its letters in alphabetical order. It splits the string into an array of characters, sorts the array, and then joins the sorted characters back into a string.
Visual Presentation:

Sample Solution:
JavaScript Code:
Output:
Phnoty Eceeirssx
Live Demo:
Flowchart:

ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that sorts only the alphabetic characters of a string while preserving the positions of non-alphabet characters.
- Write a JavaScript function that alphabetically sorts the letters of a string in a case-insensitive manner, then restores the original letter casing.
- Write a JavaScript program that first sorts a string’s letters in alphabetical order and then returns the result in reverse order.
Go to:
PREV : Transform Number to Hours and Minutes.
NEXT : Check 'a' and 'b' Separated by Exactly 3 Places.
Improve this sample solution and post your code through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.