question must look confusing I have one array of Data I am looping through this data
in for loop inside forEach loop Actually I am importing Data from CSV file and than I want to create a XML file from this Data my code is below which can Help in understanding question
var array=[
{
"Date": "20-10-21",
"Narration": "Payment To Party1",
"DebitAccount0": "Party3",
"DebitAmount0": "25,000.00",
"DebitAccount1": "Party1",
"DebitAmount0": "25,000.00",
"CreditAccount0": " HDFC BANK ",
"CreditAmount0": "50,000.00"
},
{
"Date": "19-10-21",
"Narration": "Payment To Party2",
"DebitAccount0": "Party1",
"DebitAmount0": "30,000.00",
"DebitAccount1": "Party2",
"DebitAmount1": "30,000.00",
"CreditAccount0": " HDFC BANK ",
"CreditAmount0": "60,000.00"
},
{
"Date": "18-10-21",
"Narration": "Payment To Party3",
"DebitAccount0": "Party 2",
"DebitAmount0": "12,500.00",
"DebitAccount1": "Party 3",
"DebitAmount1": "12,500.00",
"CreditAccount0": " HDFC BANK ",
"CreditAmount0": "25,000.00"
}
];
var XMLfile="<ENVELOPE>"+"<HEADER>"+"<TALLYREQUEST>Import Data</TALLYREQUEST>"+"</HEADER>"+"<BODY>"+"<IMPORTDATA>"+"<REQUESTDESC></REQUESTDESC>"+"<REQUESTDATA>"+"<TALLYMESSAGE>";
array.forEach((array,index)=>{
XMLfile+="<VOUCHER>"+"<DATE>"+array.Date+"</DATE>"+"<NARRATION>"+array.Narration+"</NARRATION>"+"<VOUCHERTYPENAME>"+voucherType+"</VOUCHERTYPENAME>"+"<VOUCHERNUMBER></VOUCHERNUMBER>";
for(i=0;i<debitcount;i++)
XMLfile+="<ALLLEDGERENTRIES.LIST>"+"<LEDGERNAME>"+array.DebitAccount+[j]+"</LEDGERNAME>"+"<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>"+"<AMOUNT>"+"-"+array.DebitAmount[j]+"</AMOUNT>"
+"</ALLLEDGERENTRIES.LIST>";}
for(j=0;j<creditcount;j++)
XMLfile+="<ALLLEDGERENTRIES.LIST>"+"<LEDGERNAME>"+array.CreditAccount+[j]+"</LEDGERNAME>"+"<ISDEEMEDPOSITIVE>No</ISDEEMEDPOSITIVE>"+"<AMOUNT>"+array.CreditAmount+[j]+"</AMOUNT>"+"</ALLLEDGERENTRIES.LIST>"+"</VOUCHER>";
}
});
What I have tried:
If I try
array.CreditAccount0
than it is sawing correct answer but if I try
array.CreditAccount+[j]
it is sawing result as undefined