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? :)

  1. iterate on object properties using for(var in)
  2. 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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -