I am working on an Angular project where I want to catch all the encCharge to add them to give a total of all the encCharge in my cf's with a for function.
This is my array :
produits = [
{
cf1: {
cfTitle: 'prInfiniti30j',
encCharge: 12345.75,
encBonifie: 47730.56
},
cf2: {
cfTitle: 'prInfiniti30j',
encCharge: 18400.94,
encBonifie: 38268.56
},
cf3: {
cfTitle: 'prInfiniti30j',
encCharge: 18392.00,
encBonifie: 30570.56
},
cf4: {
cfTitle: 'prInfiniti30j',
encCharge: 0.00,
encBonifie: 15230.56
},
},
];
This is my for function and the things that I tried, but I can't get to what I am looking for.
ngOnInit(){
for (let testing in this.produits[0]) {
console.log(this.produits[0].cf1.encBonifie);
// console.log(this.produits[0].testing.encCharge);
// console.log(testing.encCharge);
}`
This is the resultat that I expect :
let totalEncCharge = this.produits[0].cf1.encCharge +
this.produits[0].cf2.encCharge + this.produits[0].cf3.encCharge +
this.produits[0].cf4.encCharge ;
console.log(totalEncCharge);
Thank you for your help