javascript compare and sort strings alphabetically

JavaScript
function sortString(str){
  var arr = str.split('');
  var sorted = arr.sort();
  return sorted.join('');
}Copy
Source

Also in JavaScript: