i have the following two array objects
const plan = [
{Item_ID : 01, Date:"2020-04-01", Items:"10"},
{Item_ID : 02, Date:"2020-04-01", Items:"20"},
{Item_ID : 03, Date:"2020-04-02", Items:"40"},
{Item_ID : 05, Date:"2020-04-03", Items:"10"},
];
const actual = [{Date:"2020-04-01", Actual_Items:"15"},
{Date:"2020-04-02", Actual_Items:"40"},
{Date:"2020-04-05", Actual_Items:"50"},
];
these two array shows planned sales and actual sales, based on these two array im trying to create the below array
const plan = [
{Item_ID : 01, Date:"2020-04-01", Items:"10", Actual_Items:"15"},
{Item_ID : 02, Date:"2020-04-01", Items:"20", Actual_Items:"15"},
{Item_ID : 03, Date:"2020-04-02", Items:"40", Actual_Items:"40"},
{Item_ID : 05, Date:"2020-04-03", Items:"10", Actual_Items:"0"},
{Item_ID : null, Date:"2020-04-04", Items:"0", Actual_Items:"0"},
{Item_ID : null, Date:"2020-04-05", Items:"0", Actual_Items:"50"},
];
so based on the planned array if these is actual sales done for that day we show otherwise show 0. if nothing was planned but sales was done then Item_ID will be null Items will be null but Actual_Items need to show the number of sales.
I've created bellow map function maybe completely wrong logic and i was not able to continue future, any idea how to create this final array
let op = plan.map((e,i)=>{
let temp = actual.find(element=> element.Date === e.Date)
if(temp.Actual_Items) {
e.Actual_Items= temp.Actual_Items;
}
return e;
})
console.log(op);