Tuesday, April 21, 2015

jquery calculate sum of array elements

  var sum = 0;
            var array = [1, 2, 3, 4, 5];

            $.each(array, function (index, value) {
                sum = sum + value;
            });

            alert(sum);

No comments:

Post a Comment