Use for loop to sum elements from array - Node.js Array

Node.js examples for Array:Sum

Description

Use for loop to sum elements from array

Demo Code

Array.prototype.sum = function () {
  var sum = 0;/* ww w.j  a  v  a  2  s.  co m*/

  for (var i = 0, l = this.length; i < l; i++) {
    sum += this[i];
  }

  return sum;
};

Related Tutorials