JavaScript: Sort the characters of a string Alphabetically
JavaScript fundamental (ES6 Syntax): Exercise-143 with Solution
Sort String Alphabetically
Write a JavaScript program to sort the characters of a string Alphabetically.
- Use the spread operator (...), Array.prototype.sort() and String.prototype.localeCompare() to sort the characters in str.
- Recombine using String.prototype.join('').
Sample Solution:
JavaScript Code:
Output:
aabbceg 123467aflnosx
Visual Presentation:
Flowchart:

Live Demo:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that sorts the characters of a string in alphabetical order.
- Write a JavaScript function that takes a string and returns a new string with its letters sorted, ignoring case.
- Write a JavaScript program that sorts a string’s characters and then reverses the sorted order.
Go to:
PREV : Lowest Index for Sorted Insertion.
NEXT : Intersection of Two Arrays.
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.