This is my array:
let a = [
{
IsGroup: true,
Name: "Antonia Doyle"
},
{
IsGroup: false,
Name: "Dana Gray"
},
{
IsGroup: false,
Name: "Amber Banks"
},
{
IsGroup: false,
Name: "Geoff Neal"
},
{
IsGroup: true,
Name: "Nina Hartley"
},
{
IsGroup: false,
Name: "Elizabeth Warren"
},
{
IsGroup: false,
Name: "Ghengis Khan"
},
{
IsGroup: true,
Name: "Masta Razz"
}
];
I can't see to sort it by IsGroup and then Name. However, it doesn't seem to be working. My code so far:
let b = [];
b = a;
b.sort(byGroupThenName);
function byGroupThenName(a, b) {
return b.IsGroup - a.IsGroup || (a.Name - b.Name ? -1 : 1);
}
NaN, regardless of the values of the non-numeric strings.a.Name.localeCompare(b.Name), which will give the exact kind of result you need for sorting.