Je souhaite comparer 2 tableaux d'objets et mettre à jour l'objet correspondant ainsi que le nombre total dans l'objet.
let arr1 = [{status: 'Total', count: 0, text: 'Total applications'},
{status: 'submitted', count: 0, text: 'Applications submitted'},
{status: 'Rejected', count: 0, text: 'Applications rejected'}]
let arr2 = [
{status: "submitted", count: 20} ,
{status: "Rejected", count: 10}
]
fonction
let finalResult = arr2.map(function(a){
var result=arr1.filter(b=> a.status==b.status ? {...a, count:b.count} : arr1[0].count:arr1[0].count );
return result
})
Le résultat final devrait être le suivant :
[{status: 'Total', count: 30, text: 'Total applications'},
{status: 'submitted', count: 20, text: 'Applications submitted'},
{status: 'Rejected', count:10, text: 'Applications rejected'}
]