javascript - Sum all properties in object -
i have following object:
{"speed":299,"equipment":49,"teleabb":49,"additional":50,"optional":"299"}
i want sum values , print out. how can sum properties values? :)
- iterate on object properties using
for(var in)
- use
parseint
since of integers in string form
var obj = {"speed":299,"equipment":49,"teleabb":49,"additional":50,"optional":"299"}; var sum = 0; for(var key in obj){ sum += parseint(obj[key]); } document.write(sum);
Comments
Post a Comment