JSON: (The array within this.schedulerForm.get("schedularList").value contains the following array:
const result = [{
formula_id:1,
quantity1:10,
quantity2:20,
quantity3:40
}]
Conversion JSON: (The above JSON array contains 1 object with 3 quantity values. I need to separate the quantity values into individual objects with the same formula_id, along with month and year. The output should be as shown below.)
const result = [{
formula_id:1,
year:this.year,
month: this.month,
quantity:10
},
{
formula_id:1,
year:this.year,
month: this.month,
quantity:20
},
{
formula_id:1,
year:this.year,
month: this.month,
quantity:40
}]
component.ts:
month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"];
year = new Date().getFullYear();
getDate(n){
const date = new Date();
return date.getMonth() + n;
}
save() {
console.log(this.schedulerForm.get("schedularList").value)
}