9951 explained code solutions for 126 technologies


javascriptGet sum of array of numbers


[1, 2, 3, 4].reduce((total, x) => total + x)ctrl + c
[1, 2, 3, 4]

test array to get the sum for

.reduce(

executes specified function for each element, docs

(total, x)

each element of an array x will be added to total variable