javascript - Multiply the object properties -


someone tell me how multiply object's properties? need object multiplied count of property price , put together

var menu = [          {             "id": 5,           "price": 13,           "count": 2        },        {             "id": 8,           "price": 7,           "count": 3        },        {             "id": 9,             "price": 17,             "count": 1        }     ]  var sum = 0; (var key in menu) {     (var key1 in menu[key]) {         //console.log(key1);         if (key1 == 'price'){             price += menu[key][key1];         }      }  } 

but have no idea how multiply count property

suppose want calculate sum

var menu = [      {      "id": 5, "price": 13, "count": 2 }, {      "id": 8, "price": 7, "count": 3 }, { "id": 9, "price": 17, "count": 1 } ];      var sum = 0, item;      for(item in menu)      {        sum += menu[item].price * menu[item].count;      }      console.log(sum);


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -