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®ion=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);