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.