#problem with sum array

2 messages · Page 1 of 1 (latest)

sleek thunder
#

I'm trying to sum an array getting numbers from mongodb
the numbers is 56,4,4,3,2,2
and it gave me in console 056,4,4,3,2,2
it must be 56+4+4+3+2+2 = 71

                const total = await data.number
                    .map((num, i) => num.times)

                const sum = [total].reduce((partialSum, a) => partialSum + a, 0);
                console.log(sum);```