Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Javascript read data only once when it is looping

Using CSV data, I am trying to create a live clock. I read data like this,

$(document).ready(function() {
    $.ajax({
        type: "GET",
        url:"d741a.csv",
        dataType: "text",
        success: function(data) {processData(data);}
     });
});


function processData(allText) {
    var allTextLines = allText.split(/\r\n|\n/);
    var headers = allTextLines[0].split(',');
    const result = allTextLines.slice(1).reduce((sum, arr) => {
            arr.split(',').forEach((v, i) => {
                sum[i] = (sum[i] || 0) + Number(v.trim());
            })
            return sum;}, []);
        //console.log(result[4]/36035);
    var lines = [];

    for (var i=1; i<allTextLines.length; i++) {
        var data = allTextLines[i].split(',');
        if (data.length == headers.length) {

            var tarr = [];
            for (var j=0; j<headers.length; j++) {
                tarr.push(data[j]);
            }
            //lines.push(tarr);
        }
    }
    ...calculate numbers...
    var date2 = new Date(final_year, final_month-1, final_day, 00, 00, 00);
    return date2
}

In this function, I read data, calculate the numbers and create the date. And I connect this to the live clock as follows:

function startClock(){
    var last_date = processData("d741a.csv").getTime();
    //console.log(last_date);

    ....Code

    document.getElementById('txt').innerHTML =  
    "&nbsp;"+year+" Year "+ day +" Day "+ hour +":"+ minute +":"+second;
    setTimeout(startClock, 1000);
}

But when I run it, it calculates numbers only once. Otherwise, I get NaN value and see NaN : NaN : NaN for the clock. Why it works only once? What should I fix?

Example of error: NaN values

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda