Use reduce() to group objects by a property value. The accumulator builds an object where keys are categories.
const items = [
{ type: "fruit", name: "apple" },
{ type: "veggie", name: "carrot" },
{ type: "fruit", name: "banana" }
];
const grouped = items.reduce((acc, item) => {
acc[item.type] = acc[item.type] || [];
acc[item.type].push(item);
return acc;
}, {});