How to pass variable to function in for loop?
How can i get the country details into CronJob - onTick Method, It always get the last country details into the method.
for (var i = 0; i < totalCountries; i++) {
var country = countries[i];
var newArticleJob = new CronJob({
cronTime: '0 */1 * * * *',
onTick: function () {
console.log('Job triggered to fetch new articles for timezone: ' + i);
//firebaseDataServices.loadNewArticles();
},
start: false,
timeZone: country.tz
});
newArticleJobs.push(newArticleJob);
}
for (var i = 0; i < totalCountries; i++) {
newArticleJobs[i].start();
}