Jump to content

How Can I Add Values From My Arrays?


inktherapy

Recommended Posts

You could write a custom method - I don't think there is anything predefined for this.

Array.prototype.total = function() {	var value = 0;	for (i = 0; i < this.length; i++) {		value += this[i];	}	return value;}

Then call it:

var x = [2, 1, 4];alert(x.total()); //alerts 7

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...