Одно из решений может быть таким:
let addOnFeatures = [
{"name": "feature1", id: 101, cost: 100},
{"name": "feature2", id: 102, cost: 200},
{"name": "feature1", id: 103, cost: 300},
{"name": "feature3", id: 104, cost: 40}
];
var res={};
addOnFeatures.forEach(i=>{
if(!res[i.name]){
res[i.name] = [{id: i.id, cost:i.cost}]
}else{
res[i.name].push({id: i.id, cost:i.cost})
}
}
);
console.log(res)
Или это
let addOnFeatures = [
{"name": "feature1", id: 101, cost: 100},
{"name": "feature2", id: 102, cost: 200},
{"name": "feature1", id: 103, cost: 300},
{"name": "feature3", id: 104, cost: 40}
];
var res2={};
addOnFeatures.forEach(i=>{
res2[i.name] = res2[i.name] ? [...res2[i.name],...[{id: i.id, cost:i.cost}]] :[...[{id: i.id, cost:i.cost}]]
}
);
console.log(res2)