Hi I have an array or users and courses.
I need to sort by the users last name, however i can't seem to figure it out what I need to do to split the name.
Below is what I have that currently only sorts by first name.
const userarray = [
{ course: "Math", user: "Steve Lewis" },
{ course: "English", user: "James Rollo" },
{ course: "IT", user: "Suzanne Collins" }
]
userarray.sort(function(a, b) {
return a.user.toLowerCase().localeCompare(
b.user.toLowerCase()
);
});
console.log(userarray);