I am facing a scenario where I have an array
structured as follows:
[
{ "Fare":10, "TotalFare":30 },
{ "Fare":20, "TotalFare":50 },
{ "Fare":30, "TotalFare":100 }
]
My objective is to accumulate all the fare values into a single variable at index 0.
For instance, accessing array[0].fare
should yield the total amount of 60
I understand that this can be achieved with a for loop such as array[0].fare += array[i].fare
However, considering that my array contains data from 64/65 columns which need to be summed up, using the above method would make the code extremely lengthy,
Hence, I am wondering if there is a more efficient way to achieve this task?
Any suggestions or recommendations on how to approach this situation are highly appreciated.