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

108
Views
Global Scope and While loop Scope- JavaScript

Why var ProductArr=[] is not accessible inside the while loop, and how can I access it?

What is the solution if I want to continue the array and reinitialize every time in a loop.

Also is there any way I can access the while variable outside?

        var productArr = [];
        while(await page.$(".paging-next.ng-star-inserted .iconAct-Chevron_Right")){
          var grabProducts = await page.evaluate(() => {
            let products = document.querySelectorAll(".ng-tns-c226-3.ng-trigger.ng-trigger-staggerFadeInOut.product-grid .shelfProductTile-description a");       
            //var productArr = [];
            products.forEach(tag => {
                productArr.push(i+' '+tag.innerText) 
                i++;           
            });
            return productArr;
        });
        await page.click(".paging-next.ng-star-inserted .iconAct-Chevron_Right");
        await page.waitForTimeout(5000);
      }
about 4 years ago · Juan Pablo Isaza
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!