I need help figuring out how to calculate the sum of multiple arrays within an array of objects. Here's the code I have:
const employeeList = [
{
"name": "Ahmed",
"scores": [
"5",
"1",
"4",
"4",
"5",
"1",
"2",
"5",
"4",
"1"
]
},
{
"name": "Jacob Deming",
"scores": [
"4",
"2",
"5",
"1",
"3",
"2",
"2",
"1",
"3",
"2"
]
}];
var sum = 0;
for(let i = 0; i < employeeList.length; i++){
var eachScore = employeeList[i].scores;
const b = eachScore.map(Number);
console.log(b);
sum += parseInt(b);//this is the code that doesn't work
}
console.log(sum);
I'm able to display the arrays in the console, but I can't seem to figure out how to properly sum up the values in each array. Using parseInt with concatenate or simply give me the length of the array instead of the sum. I think using the .split() method could help split the arrays and sum them individually, but I haven't quite nailed down the implementation yet.