Javascript de ordem de ordem alfabética
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;
});
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))
var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort((a, b) =>
a.localeCompare(b)//using String.prototype.localCompare()
);