-1

I'm trying to sort the below rendered list of names into alphabetical order. I think I would use the sort method but I'm not sure how to do it? Here's what I have:

 useEffect(() => {
    if (selectedPeople.length > 0) {
        let allSources = [];
        let sharedSources = [];

        const duplicateSources = selectedPeople.map(user => {
            return Object.keys(user.groups);
        }).flat();
  • You should add a tag for what language you're working in – camille Feb 24 '21 at 20:37
  • 1
    Does this answer your question? [Sort objects in an array alphabetically on one property of the array](https://stackoverflow.com/questions/8900732/sort-objects-in-an-array-alphabetically-on-one-property-of-the-array) – 0stone0 Mar 22 '21 at 18:47

1 Answers1

1
let arr = ["Ravi", "Aman", "Surya", "Rohit"];
arr.sort()

OUTPUT : ["Aman", "Ravi", "Rohit", "Surya"]

Simply use: arr.sort() This will sort list alphabetical order.