let array = [
{
category: 'Animals',
type: 'something'
},
{
category:'Animals',
type: 'some'
},
{
category: 'Animals',
type: 'something'
},
{
category: 'Human',
type: 'some'
},
{
category: 'Human',
type: 'some2'
},
{
category: 'Human',
type: 'some2'
}
]
const grouped = arr.reduce((acc, n) => {
(acc[n.category] = acc[n.category] || []).push(n.type);
return acc;
}, {});
const html = `
<ul>${Object.entries(grouped).map(([ k, v ]) => `
<li>
${k}
<ul>${[...new Set(v)].map(n => `
<li>${n}</li>`).join('')}
</ul>
</li>`).join('')}
</ul>`;