• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

119
Views
innerhtml not print full array

I'm using innerhtmal for output but the problem is it shows 1 less value the array I cant find the problem.

enter image description here

enter image description here

await fetch(urlbody, bodyrequestOptions)
  .then((response) => response.json())
  .then((payload) => {
      console.log(payload)

      payload.map(({
        TRANS_NO,
        TRANS_DATE,
        DR_AMT,
        CR_AMT,
        PARTICULAR
      }, index) => {
        /* Calculatation*/
        oprningbalance += CR_AMT
        oprningbalance -= DR_AMT

        document.getElementById('output2').innerHTML += `<tr>
          <td>${index + 1}</td>
          <td class="text-tiny text-break">${moment(TRANS_DATE).format('LLL')}</td>
          <td class="text-tiny">${TRANS_NO}</td>
          <td class="text-tiny">${DR_AMT.toFixed(2)}</td>
          <td class="text-tiny">${CR_AMT.toFixed(2)}</td>
          <td class="text-tiny">${oprningbalance.toFixed(2)}</td>
          <td class="text-tiny text-break">${PARTICULAR}</td>
        </tr>`
        total_dr += DR_AMT
        total_cr += CR_AMT
      })
about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try this instead

document.getElementById('output2').innerHTML = payload.map(({TRANS_NO,TRANS_DATE,DR_AMT,CR_AMT,PARTICULAR}, index) => {
  /* Calculatation*/
  oprningbalance += CR_AMT
  oprningbalance -= DR_AMT
  total_dr += DR_AMT
  total_cr += CR_AMT
  return `<tr>
          <td>${index + 1}</td>
          <td class="text-tiny text-break">${moment(TRANS_DATE).format('LLL')}</td>
          <td class="text-tiny">${TRANS_NO}</td>
          <td class="text-tiny">${DR_AMT.toFixed(2)}</td>
          <td class="text-tiny">${CR_AMT.toFixed(2)}</td>
          <td class="text-tiny">${oprningbalance.toFixed(2)}</td>
          <td class="text-tiny text-break">${PARTICULAR}</td>
        </tr>`
}).join("")
about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error