I have the following arrays:
[{id:0,name:'Weight',option:'250'},{id:0,name:'Roast',option:'Medium'}]
[{id:0,name:'Weight',option:'250'},{id:0,name:'Roast',option:'Light'}]
I need to merge them in something like:
[{id:0,name:'Weight',options:['250']},{id:0,name:'Roast',options:['Medium','Light']}]
I tried to nest some loops also tried with merge, push and spread operators but I can't solve it
result.forEach((att) => {
let newoptions = [];
console.log('att', att.attributes);
att.attributes.forEach((id, idx) => {
console.log('id', id);
newoptions = [...newoptions, { option: id.option }];
newAttr[idx] = { name: id.name, options: newoptions };
});
});