How to alphabetically sort an array by first name in JavaScript?

I have an array containing user objects, and I need to arrange them based on their first names in alphabetical order using JavaScript. What steps should I take to achieve this? Here is an example of one of the objects in the array:

const member = {
   profile: null,
   contact: "[email protected]",
   firstName: "Anna",
   userId: 318,
   latestAvatar: null,
   recentMessage: null,
   lastName: "Nickson",
   userNickname: "anny"
};

Hey Dave, you can sort the array by using the sort() method. Here's a quick solution:

usersArray.sort((a, b) => a.firstName.localeCompare(b.firstName));

This will sort the objects in usersArray by firstName alphabetically. Cheers!