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

163
Views
How to compare Items within a Listbox that I created by reading items from Database

I have a function (as below) in which I am reading a database response and calculating the timespent by each jobs in a machine. So here the entries can be similar or have same unique id and currently it is displayed in a way where it will display out all the entries even when Its similar. So what i want to do is find a way to compare the entries within the list that i read and if they have save unique id then add the time spent and display out the final one.

function displayMachineTimeSpent(machineId, response) {

    let listbox = document.getElementById("machine_time");
    $('#machine_time').empty();

    var b = "Not yet Completed";

    if(machineId in response) response = response[machineId];

    for(key in response)
    {
        if('machineStartTime' in response[key])
        {   
            let divContainer = document.createElement("li");

            let start = response[key]['machineStartTime'];
            let end = response[key]['machineStopTime'];
            
            //Calculating the difference in timetsamps and changing it to Hours: Min format.
            const timeDiffInMs = new Date(end).getTime() - new Date(start).getTime()

            var B = "Process was not ran in correct order.";
            var Time;
            if(timeDiffInMs < 0) {
                Time = B;
            } else {
                Time = MstoHTIME(timeDiffInMs);
            }
        
            divContainer.innerText = key + " == " + Time;
            listbox.appendChild(divContainer);
        }
    }
}

The output with current scenario is as: See link

I want to find a way to add all those times into one entry within this method(listbox) itself.

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!