0

How to get total for array?

How to get total for array?

10th Feb 2017, 2:01 PM
Etay Cohen
Etay Cohen - avatar
1 Respuesta
+ 1
var a=[ ... ]; var count_items_of_a=a.length; // total as meaning number of elements var sum_items_of_a=sum_items(a); // total as meaning sum of elements function sum_items(arr) { // custom function to sum all elements of an array var r=arr[0]; for (var i=1; i<a.length; i++) r+=r; return r; }
10th Feb 2017, 3:19 PM
visph
visph - avatar