Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!