+ 2

help with sum of elements of an array in js

I'm in the js arrays lesson in practice 39.2 and I don't know how to add the elements of an array without knowing how many they are, it is the problem of adding the points of levels of a game. someone who has solved it to guide me please.

8th Apr 2021, 11:54 AM
Richard
2 Answers
+ 3
const sum = arr.reduce((s,v)=>s+v);
8th Apr 2021, 12:00 PM
CalviŐČ
CalviŐČ - avatar
+ 2
Thanks
8th Apr 2021, 12:09 PM
Richard