( ! ) Notice: Undefined index: description in /home/prototurk.com/public_html/app/controller/demo.php on line 171 Call Stack # Time Memory Function Location 1 0.0002 364792 {main}( ) .../index.php:0 2 0.0039 446536 require( '/home/prototurk.com/public_html/app/controller/demo.php' ) .../index.php:101
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)