On the problem of data conversion

let fundList = [

]
{
    name: "a",
    id: 0,
},
{
    name: "b",
    id: 1,
}

];
let beforeData = [

{
    "approved_amount_sum": 44200,
    "date": "2018-08-07",
    "a": 44200,
    "a_rate": 1,
},
{
    "approved_amount_sum": null,
    date: "2018-08-08",
},

]
let data = [

{
    "approved_amount_sum": 44200,
    "date": "2018-08-07",
    "a": 44200,
    "a_rate": 1,
    "b": null,
    "b_rate": null,
},
{
    "approved_amount_sum": null,
    "date": "2018-08-08",
    "a": null,
    "a_rate": null,
    "b": null,
    "b_rate": null,
},

]
you need to match name and beforeData according to the name in fundList, add those that are not in beforeData, and add the variable of name_rate. I would like to ask the passing god how to write this

.
Apr.09,2021

let fundObj = fundList.reduce((t,c)=>{
    t[c.name] = null;
    t[c.name + '_rate'] = null;
    return t;
}, {});

let afterData = beforeData.map(o => Object.assign({}, fundObj, o));
console.log(afterData);
Menu