Answers for "how to sort names alphabetically in js"

10

js sort alphabetically

users.sort((a, b) => a.firstname.localeCompare(b.firstname))
Posted by: Guest on October-19-2020
3

js sort alphabetically

users.sort(function(a, b){
    if(a.firstname < b.firstname) { return -1; }
    if(a.firstname > b.firstname) { return 1; }
    return 0;
})
Posted by: Guest on July-13-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 "how to sort names alphabetically in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language