I have two array list list1 and list2, property name matches, then sum all the qty of list1 and list2 matched object, return updated qty of list1
function resultantArray(list1, list2){
let sum = list2.map(o => o.qty|| 0).reduce((a, c) => { return a + c });
list1.forEach(item=>{
list2.find(elm => elm.productcode == item.productcode).qty= sum;
});
}
var list1 = [
{id:1, name: "IN",qty: 1},
{id:2, name: "TH"},
{id:3, name: "AU"}
]
var list2 = [
{id:3, name: "IN", qty:1},
{id:5, name: "IN", qty:1},
{id:4, name: "TH", qty: 2},
{id:1, name: "SG", qty: 3}
]
Expected Output:
[
{id:1, name: "IN",qty: 3},
{id:2, name: "TH", qty: 2},
{id:3, name: "AU"}
]
THbe qty2in output object?... What happens to items missing by name in list 2?THshould be included, inlist2missing by name also should be included,list2the entry forTHhas noqty? What does it mean when there is noqtyproperty? Is it equivalent withqty: 0?qty: 0