javascript - How would I get the specific object in json stringify output? -


can me on how specific object in json?

i want sum 3 in stringify ouput.

var arr_question = [{"$1z_1":3,"$2o_1":"question 1."},{"$1z_1":3,"$2o_1":"question2."},{"$1z_1":3,"$2o_1":"question3."}];    console.log("output: "+arr_question.$1z_1);  console.log("arrays: "+arr_question)

you can use foreach iterate on array , add value of each object in array declared "total"variable total of values.

var arr_question = [{"$1z_1":3,"$2o_1":"question 1."},{"$1z_1":3,"$2o_1":"question2."},{"$1z_1":3,"$2o_1":"question3."}];    var total = 0;  arr_question.foreach(function(obj){    total += obj.$1z_1;   })    console.log("output: " + total); // gives "output: 9"


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -