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"
var names = ["Peter", "Emma", "Jack", "Mia"];
var sorted = names.sort(); // ["Emma", "Jack", "Mia", "Peter"]