Javascript Array sum(key)

Description

Javascript Array sum(key)

Array.prototype.sum = function (key) {
  return this.reduce((memo, item) => memo + (key ? item[key] : item), 0)
}



PreviousNext

Related