Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Recursive function not incremeanting its own parameter

var documentURLs = ["maca.pdf", "maca2.pdf"]
function printDocuments(index){
   if(index > documentURLs.length){
        return;
   }
   else {
     printJS({
       printable: documentURLs[index],
       type: 'pdf',
       onPrintDialogClose: function () {
         console.log(index);
          printDocuments(index++)
       }
     })
   }
}
<button type="button" onclick="printDocuments(0)">Print</button>

This is not incrementing the index, always print first document and it is not stopping

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It behaves exactly as it should. If you want to call printDocuments with the next index, you should use printDocument(++index) or justprintDocument(index+1), because it's the least confusing one. i++ returns current value of i and then adds 1. ++i first adds 1 and returns that increased value (so i+1).

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!