I have a logical problem that is making me mad in Angular. I have a nested array of objects, which look likes it :
data : _lignesVent [{
0: {_Status: false, _lstVentilation: Array(2)}
1: {_Status: false, _lstVentilation: Array(0)}
2: {_Status: false, _lstVentilation: Array(5)} }]
each object represents an employee. within each "_lstVentilation" object, there is another array of object like this :
_lstVentilation: Array(2)
0: {_Quantite: 6, _QuantiteTimeStamp: 21600}
1: {_Quantite: 4, _QuantiteTimeStamp: 14400}
What I am trying to to do, is to sum each quantity (by employee). But so far, i only succeeded in summing every "_Quantite" from all of the objects, like that :
addVentilationQuantity() {
var totalQuantity = 0;
this.data.lignesVent.forEach(ventil => {
ventil._lstVentilation.forEach(quantite => {
for(var i = 0; i < quantite._Quantite.length; ++i){
totalQuantity += quantite._Quantite[i];
}
})
})
return totalQuantity;
}
And in the HTML I just call the function. So, As a result, for all my employees, there is always the same number, the sum of all the quantity, and not the sum of their quantity.
Can someone help me with this one? Thanks.