Answers for "sort list javascript alphabetically"

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 string array sort alphabetically

var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort((a, b) =>
   a.localeCompare(b)//using String.prototype.localCompare()
);
Posted by: Guest on August-12-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

Code answers related to "sort list javascript alphabetically"

Code answers related to "Javascript"

Browse Popular Code Answers by Language