I have this loop:
for (let i = 0; i < rows.length; i++) {
let sessionString = rows[i][weekday];
//finalSessionString is the variable for splitting the string into 4 parts
const finalSessionString = sessionString.split('|');
//finalSessionString0 is the string that holds the value of (ex) 01 11 * * 1
const finalSessionString0 = finalSessionString[0]
//finalSessionStringPhoneNumber gets phone number from finalSessionString
const finalSessionStringPhoneNumber = finalSessionString[1]
//finalSessionStringName is getting the name of the person training
const finalSessionStringName = finalSessionString[2]
//finalSessionStringTrainerName is getting the name of the trainer
const finalSessionStringTrainerName = finalSessionString[3]
console.log("kk: " + finalSessionString[1])
console.log(finalSessionString0)
console.log(finalSessionStringPhoneNumber)
console.log(finalSessionStringName)
console.log(finalSessionStringTrainerName)
var textJob = new cronJob( finalSessionString0, function(){
client.messages.create( { to: finalSessionStringPhoneNumber, from:'12055578708', body:'hello ' + finalSessionStringName + ', Your training session just finished with ' + finalSessionStringTrainerName}, function( err, data ) {
if (err) {
console.log("err: " + err)
}
console.log(data)
});
},
null, true)
finalSessionString.length = 0
}
finalSessionString is an array, that produces a response like so:
[
'05 10 * * 2',
'1234567890',
'Gianluca A',
'gianluca@mmm.com'
]
so after i split up the array into multiple parts, I want it to clear the array length, because I am also running a cronjob which runs every 45 seconds, so every 45 seconds it is inserting a new value into the array! So after every time it inserts a new record into the array, I need it to clear it first. that's what I tried to do here
finalSessionString.length = 0
but it isn't working, because i got 5 text messages after 5 rounds of the cronjob running. So how can i fix this?
If you just want to clear the aray before the Cron job just do
finalSessionString = [ ];
finalSessionString.push(value);