I have an array of objects which I have to loop through and group duplicate values by property name "tagColor", then the grouped objects I need to sort by name. I achieved first step I sorted by color, now I need to sort only those groups by name, implementing this in angular 4, typescript
Here is array list
tags = [
{
"tagType": {
"name": "a",
"tagColor": "#0000FF"
}
},
{
"tagType": {
"name": "a",
"tagColor": "#FF0000"
}
},
{
"tagType": {
"name": "c",
"tagColor": "#FF0000",
}
},
{
"tagType": {
"name": "b",
"tagColor": "#FF0000",
}
},
{
"tagType": {
"name": "b",
"tagColor": "#0000FF",
}
}
]
my function that sorts by tagColor:
tags.sort((a, b) => a.tagType.tagColor.localeCompare(b.tagType.tagColor));
this groups by color only, but how also to sort those groups alphabetically?
