Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to sort array alphabetically in javascript

function alphabeticalOrder(arr) {
  return arr.sort((a, b) => a < b ? -1 : 1)
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
// [ 'a', 'a', 'c', 'd', 'g', 'z' ]
 
PREVIOUS NEXT
Tagged: #sort #array #alphabetically #javascript
ADD COMMENT
Topic
Name
7+4 =