views:

25

answers:

1

Hi,

I need to figure out the value of data strings with jquery, for example like this:

 { label: "Beginner",  data: 2},
 { label: "Advanced",  data: 12},
 { label: "Expert",  data: 22},

to add them up.

Something like:

var sum = data1+data2+data3;
alert(sum);

So the result for this example would be 36.

Appreciate your help!

Nicole

+3  A: 

Something like this?:

var data = [
   { label: "Beginner",  data: 2},
   { label: "Advanced",  data: 12},
   { label: "Expert",  data: 22} 
]
var sum = 0;

for each (var d in data) {
    sum += d.data;
}

alert(sum);
Felix Kling
it works! thank you very much!
Nicole Loyal-Windham
awesome please accept his answer then
mcgrailm