const products = [
{
name: "NT1-A Condenser Mikrofon",
brand: "Rode"
},
{
name: "iPhone XS",
brand: "Apple"
},
{
name: "SmartLav Plus+ Yaka Mikrofonu",
brand: "Rode"
},
{
name: "M-AUDIO Keystation 61",
brand: "M-Audio"
}
]
const groupBy = (array, prop) => {
return array.reduce((acc, obj) => {
let key = obj[prop]
if (!acc[key]){
acc[key] = []
}
acc[key].push(obj)
return acc
}, {})
}
let groupedProducts = groupBy(products, 'brand')
console.log(groupedProducts)