Sum all elements from array - Node.js Array

Node.js examples for Array:Sum

Description

Sum all elements from array

Demo Code


Array.prototype.sum = function() {
  var sum = 0;//  www  .  java 2  s . c  o  m
  for (var i = 0, l = this.length; i < l; i++) {
    sum += this[i];
  }
  return sum;
};

Related Tutorials