Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
clear array while inside loop javascript

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you just want to clear the aray before the Cron job just do

finalSessionString = [ ];
finalSessionString.push(value);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda