const states = ["BR", "UP"];
const template = [
{
"State": "",
"allotment": 25622
},
{
"State": "",
"expenditure": 1254
}
];
let totalRecords: any[] = [];
states.forEach(state=>{
const cc = template.map(record=> {record.State = state; return record})
console.log(state, cc);// here i get the indiviual record set.
totalRecords = totalRecords.concat(cc);
})
console.log(totalRecords);
here i am trying to get a concatenated list of template with different states, but somehow it is overwriting the previous records. although as seen in the console after adding map to template, a proper record set is seen. still it is not concatenating properly.
how to do it properly as required result is
[{
"State": "BR",
"allotment": 25622
}, {
"State": "BR",
"expenditure": 1254
}, {
"State": "UP",
"allotment": 25622
}, {
"State": "UP",
"expenditure": 1254
}]