JavaScript array ordo abjad
arr.sort(function(a, b) {
return a === b ? 0 : a < b ? -1 : 1;
});
Yawning Yacare
arr.sort(function(a, b) {
return a === b ? 0 : a < b ? -1 : 1;
});
var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort(function (a, b) {
return a.localeCompare(b); //using String.prototype.localCompare()
});
// items is ['adieu', 'café', 'communiqué', 'éclair', 'premier', 'réservé']
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' ]
users.sort((a, b) => a.firstname.localeCompare(b.firstname))
// Alphabetically
const ascending = data.sort((a, b) => a[field].localeCompare(b[field]))
// Descending
const descending = ascending.reverse()
users.sort((a, b) => a.firstname.localeCompare(b.firstname))