[
{
id: 1,
name: "краски"
},
{
id: 1,
name: "краски"
},
]
[{ id: 1, name: "краски", count: 2 }, { ... }, { ... }]
const data = [
{
id: 1,
name: "краски"
},
{
id: 1,
name: "краски"
},
{
id: 2,
name: "краски"
},
{
id: 1,
name: "краски"
},
]
Object.values(data.reduce((acc, item) => {
const { id } = item
if(!acc.hasOwnProperty(id)) acc[id] = { ...item, count: 1};
else acc[id].count += 1
return acc
}, {}))