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

315
Views
Javasript foreach loop - add all values together and get the sum of all values

I have this javascript timer and I want to get all the values for each time from my database. I want to add all the numbers together and get the final result. The problem is that my timer has a specific time format.

Code

let htmlTdTime =  taskTimeRow.querySelectorAll("td:nth-child(2)");

htmlTdTime.forEach((time) => {

    let time2 = time.innerHTML
    let a2 = time2.split(":");
    let seconds2 = +a2[0] * 60 * 60 + +a2[1] * 60 + +a2[2];
    let ti2 = "";

    function timer2() {
        seconds2++;
        let hours = Math.floor(seconds2 / 3600);
        // Get minutes
        let minutes = Math.floor((seconds2 - hours * 3600) / 60);
        // Get seconds2
        let secs = Math.floor(seconds2 % 60);

        if (hours < 10) {
            hours = `0${hours}`;
        }
        if (minutes < 10) {
            minutes = `0${minutes}`;
        }
        if (secs < 10) {
            secs = `0${secs}`;
        }

        let singleTime = time.innerHTML;

        console.log(singleTime)

        ti2 = `${hours}:${minutes}:${secs}`;

        return ti2;
    }

    timer2();

})

// THIS IS WHAT I GET WHEN I CONSOLE.LOG
    // 00:00:21
    // 03:10:15
    // 00:49:31
    // 30:00:53
    // 00:45:21
    // 12:32:56
    // 00:00:56
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!