Answers for "js sort alphabetically string with numbers"

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

Code answers related to "js sort alphabetically string with numbers"

Code answers related to "Javascript"

Browse Popular Code Answers by Language