RE: javascript - adding the values in an array

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 26 Oct 2007 14:14:37 -0400

 Declare total outside of the loop, and then keep adding num[i] to total

Take care,
Sina

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Lamar Upshaw
Sent: Friday, October 26, 2007 12:21 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: javascript - adding the values in an array

Ok, here's an easy one for someone, although difficult for me! lol *smile*

I have an array in javascript:
num = New array(0,1,2,3,4);

I want to have a variable that has the added total of the values in the num
array:

total = 10;

How do I get javascript to add the values in the array and put them in to a
variable?  I've tried both the while and for loops, but it seems the value
of a variable in the loop, only applies while in the loop.

With All Respect,
Upshaw, LaMar T

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: