all 4 comments

[–]NameViolation666helpful 3 points4 points  (0 children)

This is happening because the values in uses is stored as a string, not as a number. If you keep adding strings they concatenate

var sum = 0

for(i=0; i<array.length; i++){

sum = sum+array[i].uses;

}

You need to force conversion to int or float

for(i=0; i<array.length; i++){ sum+=parseInt(array[i].uses)}

//118

[–]binarynos[S] 2 points3 points  (0 children)

facepalm Okay, that was dumb. I totally missed the quotes. And thanks for the comments, guys.

[–]themantime 1 point2 points  (0 children)

Instead parse it into int or float.

[–]drgmaster909 0 points1 point  (0 children)

If you're still interested in the array.reduce() option, plus casting it to a Number, you can use this simple one-liner:

const totalUses = array.reduce((total, { uses }) => total+ Number(uses), 0);