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

120
Views
Request and Cheerio (data scraping packages for JavaScript) prints data but will not add to array

I am trying to store tracking data from the ISS using request and Cheerio for JS, I have got to the point that I can print the data but when trying to store the data in an array it returns undefined.

data.push(tr.text().split("|")); //will not put anything in the array data

console.log(tr.text().split("|")); //does exactly what i want it to

var data = [];

function sendReq(){

request('https://spotthestation.nasa.gov/sightings/view.cfm?country=Canada&region=Newfoundland&city=Saint_Johns#.YmhIZdPMK5c', 
    function (error, response, html) {

        if (!error && response.statusCode == 200) { 
            var $ = cheerio.load(html); 
            $('table').each(function(){
                
                var tr = $(this).next(); 

                data.push(tr.text().split("|")); //wont put into array data

                //console.log(tr.text().split("|")); //works perfectly fine
                
            }); 
        }

    });
}

sendReq();

console.log(data);
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!