I have an array like this:
[
{
group: "A",
id: "1",
name: "Mike"
},
{
group: "A",
id: "6",
name: "Sherley"
},
{
group: "B",
id: "3",
name: "Charlie"
},
{
group: "C",
id: "2",
name: "Dave"
}
]
and I want to group the array based on its group. The array is already sorted by group and name. So, I make something like this:
let lastgroup = c[0].group
return <Group title={lastgroup}>
{c.map(x => {
if (lastgroup == x.group) {
return <a href={"#" + x.id}>{x.name}</a>
} else {
lastgroup = x.group
return </Group><Group title={lastgroup}><a href={"#" + x.id}>{x.name}</a> //-> What should I put here for something like this?
}
})}
</Group>
Now, that solution above does not work obviously, and is not clean. How should I close and reopen Tag? Or is there a cleaner way to do that?
Thank you