I have two array of objects from which I am trying to loop and get a new object as per requirement.
My 1st array
This the header one
let billHeader = [
{
"billno": "A1",
"companyid": "AAAA",
"pending": "Y",
"cancelled": "N",
"salesman": "admin",
"netamount": "225.0000",
"billdate": "2020-01-16",
"billtime": "11:15:29"
},
{
"billno": "A2",
"companyid": "AAAA",
"pending": "Y",
"cancelled": "N",
"salesman": "admin",
"netamount": "1500.0000",
"billdate": "2020-01-16",
"billtime": "11:18:29"
}
]
second one is buillInfo
let billInfo = [
{
"billno": "A1",
"itemcode": "1002",
"companyid": "AAAA",
"unitprice": "125.0000",
"itemname": "MANCHOW NV SOUP",
"quantity": "1.0000",
"totalamount": "125.0000",
"categoryname": "SOUP"
},
{
"billno": "A1",
"itemcode": "1001",
"companyid": "AAAA",
"unitprice": "100.0000",
"itemname": "MANCHOW V SOUP",
"quantity": "1.0000",
"totalamount": "100.0000",
"categoryname": "SOUP"
},
{
"billno": "A2",
"itemcode": "1001",
"companyid": "AAAA",
"unitprice": "300.0000",
"itemname": "MANCHOW V SOUP",
"quantity": "2.0000",
"totalamount": "600.0000",
"categoryname": "SOUP"
},
{
"billno": "A2",
"itemcode": "1003",
"companyid": "AAAA",
"unitprice": "300.0000",
"itemname": "Name Item",
"quantity": "3.0000",
"totalamount": "6300.0000",
"categoryname": "SOUP"
}
]
I want to loop through both of them and have an output exactly like this
{
"module": "outletbills",
"status": "success",
"billinfo": [
{
"billno": "A1",
"companyid": "AAAA",
"pending": "N",
"cancelled": "N",
"salesman": "admin",
"netamount": "225.0000",
"billdate": "2020-01-16",
"billtime": "11:15:29",
"billitems": [
{
"billno": "A1",
"itemcode": "1001",
"companyid": "AAAB",
"unitprice": "100.0000",
"itemname": "MANCHOW V SOUP",
"quantity": "1.0000",
"totalamount": "100.0000",
"categoryname": "SOUP"
},
{
"billno": "A498",
"itemcode": "1002",
"companyid": "AAAB",
"unitprice": "125.0000",
"itemname": "MANCHOW NV SOUP",
"quantity": "1.0000",
"totalamount": "125.0000",
"categoryname": "SOUP"
}
]
},
{
"billno": "A2",
"companyid": "AAAA",
"pending": "N",
"cancelled": "N",
"salesman": "admin",
"netamount": "1500.0000",
"billdate": "2020-01-16",
"billtime": "11:16:41",
"billitems": [
{
"billno": "A2",
"itemcode": "1001",
"companyid": "AAAB",
"unitprice": "900.0000",
"itemname": "MANCHOW V SOUP",
"quantity": "2.0000",
"totalamount": "200.0000",
"categoryname": "SOUP"
},
{
"billno": "A2",
"itemcode": "1002",
"companyid": "AAAA",
"unitprice": "125.0000",
"itemname": "MANCHOW NV SOUP",
"quantity": "1.0000",
"totalamount": "600.0000",
"unitcode": "NOS"
}
]
}
]
}
How to start? I know several methods which will help me out like map, reduce, filter but don't know how to exactly do this.