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))
*************sort String*************
1. arr.sort(function(a, b) {
return a === b ? 0 : a < b ? -1 : 1;
});
**************************************************************
2. users.sort((a, b) => a.firstname.localeCompare(b.firstname)) // Anuj Kashyap
// Alphabetically
const ascending = data.sort((a, b) => a[field].localeCompare(b[field]))
// Descending
const descending = ascending.reverse()
sort String