I have the following object and array of objects the later is a server array and the first one is a reference object that I want to use to get the values that I want from the main array and idea how to intigrate the array in to the object ? I tried to use Object.assign but no luck.
const obj1 = { day1: ['cake', 'muffin'], day2: ['grapes']};
const arrObj2: = [{name : 'cake', group 'dessert'},{name : 'muffin', group 'dessert'},{name : 'grapes', group 'vegs'}]
// Expected results
const newObject = //{
// day1: [{name : 'cake', group 'dessert'},{name : 'muffin', group 'dessert'}]
//, day2: [{name : 'grapes', group 'vegs'}]
//};
>Solution :
You should use a .reduce to map thru all entries [key, value] fromobj1 and then filter items from arrObj2 where name is in your value array
const newObject = Object.entries(obj1).reduce((p, [key, value]) => ({
...p,
[key]: arrObj2.filter(f => value.includes(f.name))
}), {})