Answers for "sort item js by alphabetical order"

16

alphabetical order array javascript

arr.sort(function(a, b) {
    return a === b ? 0 : a < b ? -1 : 1;
  });
Posted by: Guest on August-11-2020
1

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' ]
Posted by: Guest on November-15-2021
-1

javascript compare and sort strings alphabetically

function sortString(str){
  var arr = str.split('');
  var sorted = arr.sort();
  return sorted.join('');
}Copy
Posted by: Guest on February-29-2020

Code answers related to "sort item js by alphabetical order"

Code answers related to "Javascript"

Browse Popular Code Answers by Language