I'm having an array of milliseconds which I want a total of. I have tried the array.reduce and use a for-loop but all I get is total gibberish when I console it or use on the site. If I get the milliseconds summed up I could convert them to seconds and, if needed, minutes.
Code:
window.timeArray = [2493, 2109, 4424, 1971, 3411, 1834, 2418]
let totalTimeSum = 0
for (let i = 0; i < window.timeArray.length; i++) {
totalTimeSum += parseInt(window.timeArray[i])
}
document.querySelector('#score').innerText += totalTimeSum
// 1866018660, should be 15249 - 15 sec 249 millisec
Optional code:
let totalTime = (sum, value) => sum + value
let totalTimeSum = window.timeArray.reduce(totalTime)
document.querySelector('#score').innerText += totalTimeSum
// 1866018660, should be 15249 - 15 sec 249 millisec