Here is a snippet from my JSON data:
const jsonData = {
"08/23/2022": {
"One": 254,
"Two": 92,
"Three": 8
},
"08/13/2022": {
"One": 327,
"Two": 86,
},
"08/14/2022": {
"One": 431
},
}
I am looking to calculate the sum of all the values in this JSON object, regardless of the keys. For example, in this case, the total sum would be 254+92+8+327+86+431, resulting in 1198. Initially, I was only considering the first value, but I realized that approach is incorrect. I am currently using a nested loop in my code to achieve this, as shown below:
let sum = 0;
for (const [key, value] of Object.entries(jsonData)) {
Object.entries(value).forEach(val => sum += val[1])
}
Is there a more efficient or cleaner way to accomplish this task?