Is there a way to alphabetically sort the names in an array list using JavaScript? I attempted to achieve this with the following code:
const sample = [
{
name: "AddMain",
mesg: "test000"
},
{
name: "Ballside",
mesg: "test004545"
},
{
name: "TestMain",
mesg: "test00"
},
{
name: "ball",
mesg: "test004545"
},
{
name: "Main",
mesg: "test004545"
},
{
name: "alliswell",
mesg: "test004545"
}
]
sample.sort(sortBy('name', false, function(a){return a.toUpperCase()}));
Unfortunately, the sorting doesn't seem to work correctly. I am using lodash for the sortBy function and if there is a better way to do this with lodash or any other method, that would be great.