Step1:
To create nested array
Step2:
Excepting the Output of Nested Array
{
requestDate : "16-03-2023",
copyshPdRec : 1,
copyshcomment : 2
listOfSubdistricts: [{
requestDate : "16-03-2023",
copyshPdRec : 1,
copyshcomment : 2
},
{
requestDate : "16-03-2023",
copyshPdRec : 1,
copyshcomment : 2
}]
}
copyPDValueDCFT(nValue?:any){
if(this.selectedProductCat === 'DCFT') {
this.copyPd = false;
}
this.copyPdValues = [];
console.log(nValue);
nValue?.forEach((element, index) => {
console.log(index);
var roles=this.tokenStorage.getUserRole();
let objRole:any={};
objRole.type = roles.indexOf("3")!=-1 ? "SH" : roles.indexOf("5")!=-1 ? "ZH" : "RH";
let copyObjpdValues:any = {}
if(objRole.type =="SH")
{
copyObjpdValues.requestDate = element.requestDate;
copyObjpdValues.copyshPdRec = element.shPdRec;
copyObjpdValues.copyshcomment = element.shComments;
}
if(objRole.type =="ZH")
{
copyObjpdValues.zh_effective_date = element.zh_effective_date;
copyObjpdValues.copyzhPdRec = element.zhPdRec;
copyObjpdValues.copyzhcomment = element.zhComments;
}
if(objRole.type =="RH")
{
copyObjpdValues.lastapprovedDate = element.lastApprovedDate;
copyObjpdValues.copyrhPdRec = element.lrsPdRec;
copyObjpdValues.copyrhcomment = element.lrshComments;
}
//element?.listOfSubdistricts?.forEach(listelements => {
copyObjpdValues.listOfSubdistricts =[];
for(var i=0; i < element?.listOfSubdistricts?.length; i++)
{
let subObj:any ={}
if(objRole.type =="SH")
{
subObj['SHsubrequestDate'] = element?.listOfSubdistricts[i].requestDate;
subObj['SHsubshPdRec'] = element?.listOfSubdistricts[i].shPdRec;
subObj['SHsubshcomment'] = element?.listOfSubdistricts[i].shComments;
}
if(objRole.type =="ZH")
{
subObj['ZHsubzh_effective_date'] = element?.listOfSubdistricts[i].zh_effective_date;
subObj['ZHsubzhPdRec'] = element?.listOfSubdistricts[i].zhPdRec;
subObj['ZHsubcopyzhcomment'] = element?.listOfSubdistricts[i].zhComments;
}
if(objRole.type =="RH")
{
subObj['RHsublastapprovedDate'] = element?.listOfSubdistricts[i].lastApprovedDate;
subObj['RHsubrhPdRec'] = element?.listOfSubdistricts[i].lrsPdRec;
subObj['RHsubrhcomment'] = element?.listOfSubdistricts[i].lrshComments;
}
copyObjpdValues.listOfSubdistricts.push(subObj);
}
this.copyPdValues.push(copyObjpdValues);
});
}