I have made a for each loop to access numbers from a JSON array, the array will be dynamic and forever changing and so I have isolated the numbers inside a variable (the variable is inside the loop). My question is: How do I sum up the numbers that are in the variable.
I tried doing a for loop inside the loop but it didn't work.
it looks kind of like this:
const arrayhours = Array.from(json_obj); arrayhours.forEach(e=>{ const hours = parseFloat(e.hoursWorked); console.log(hours); //returns for example 1.25 9 5 8 7 as seperate objects. }); 
let sum = arrayhours.reduce((a, c) => a + +c.hoursWorked, 0);