Array de orden alfabético JavaScript
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;
});
users.sort((a, b) => a.firstname.localeCompare(b.firstname))
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
let numbers = [0, 1, 2, 3, 10, 20, 30];
numbers.sort((a, b) => a - b);
console.log(numbers);
var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort((a, b) =>
a.localeCompare(b)//using String.prototype.localCompare()
);