开发者

Get value of "data"

开发者 https://www.devze.com 2022-12-25 09:20 出处:网络
I need to figure out the value of data strings with jquery, for example like this: { label: \"Beginner\",data: 2},

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消