I am having one report array of objects which is used to show report data on the dashboard as below,
report = [
{id: "id01", code: "C001", name: "apples", type: "fruits", intime:[], quantity:[]},
{id: "id01", code: "C001", name: "grapes", type: "fruits", intime:[], quantity:[]},
{id: "id01", code: "C002", name: "apples", type: "fruits", intime:[], quantity:[]},
{id: "id01", code: "C002", name: "grapes", type: "fruits", intime:[], quantity:[]}
]
And below array as input,
record = [
{code: "C001",
records :[{intime: "15:32:12", apples: "30", grapes: "80"},
{intime: "15:32:13", apples: "34", grapes: "50"}]
},
{code: "C002",
records :[{intime: "15:32:12", apples: "56", grapes: "100"},
{intime: "15:32:13", apples: "75", grapes: "38"}]
},
]
I want to put these values to arrays of report array as per matching condition so that report array should look like,
report = [
{id: "id01", code: "C001", name: "apples", type: "fruits", intime:["15:32:12","15:32:13"], quantity:[30,34]},
{id: "id01", code: "C001", name: "grapes", type: "fruits", intime:["15:32:12","15:32:13"], quantity:[80,50]},
{id: "id01", code: "C002", name: "apples", type: "fruits", intime:["15:32:12","15:32:13"], quantity:[56,75]},
{id: "id01", code: "C002", name: "grapes", type: "fruits", intime:["15:32:12","15:32:13"], quantity:[100,38]}
]
I think , this can be achieved through array filter method in loop but that method does not seems efficient when record array is big in size. Please suggest me some better and efficient way to put values in such way.
codeas the key and the values are arrays of elements ofreport.