I am trying to count hours worked for an individual id dynamically. Currently, if I want to count the hours for id 1 for example I am having to hard code the id value and do the count. example below. I am using datatables so there will eventually be hundreds of rows
var array = [{id: 1, hours: 10},{id: 1, hours: 12}, {id: 2, hours: 6}, {id: 2, hours: 11} {id: 3, hours: 12}, {id: 3, hours: 8}]
var array = dataTable.rows().data().toArray();
array.filter((h) => {
if (h.id == '1' && (count += h.hours) > 5) {
'do something'
}
else {'do something'}
})
How do I count the hours of each 'id' dynamically without hard coding the id value thank you