Jump to content

Sort Strings

From Drywall Wiki
Revision as of 17:46, 7 January 2026 by Jlebeau81 (talk | contribs)

sort words in alphabetical order

  • // take input
  • const string = prompt('Enter a sentence: ');
  • // converting to an array
  • const words = string.split(' ');
  • // sort the array elements
  • words.sort();
  • // display the sorted words
  • console.log('The sorted words are:');
  • for (const element of words) {
  • console.log(element);

}