users.sort((a, b) => a.firstname.localeCompare(b.firstname))
const sort = (arr) => arr.slice().sort(); // default sort
const sort = (arr) => arr.slice().sort((a, b) => a - b); // simple sort
const sort = (arr) => arr.slice().sort((a, b) => a.localeCompare(b, 'en', { sensitivity: 'base' })); // language-specific sort
// function that returns a string in alphabetical order
function reorderStr(str) {
return [...str].sort().join('');
}
console.log(reorderStr("hacker")); //"acehkr"
console.log(reorderStr("javascript"));//"aacijprstv"
let fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort()
console.log(fruits)
// [ 'Apple', 'Banana', 'Mango', 'Orange' ]
var names = ["Peter", "Emma", "Jack", "Mia"];
var sorted = names.sort(); // ["Emma", "Jack", "Mia", "Peter"]