Get value of "data"
I need to figure out the value of data strings with jquery, for example like this:
{ label: "Beginner", data: 2},
{ label: "Advanced", data: 12开发者_StackOverflow社区},
{ 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!
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);
精彩评论