var products = [ { id: 'id1', title: 'beer1', price: '0.1' }, { id: 'id2', title: 'beer2', price: '0.1' }, { id: 'id3', title: 'beer3', price: '0.1' } ]; var list = {}; function getProduct(id) { for(var i=0; i"; html += ""; html += "
"; document.getElementById("list").innerHTML = html; } function purchase() { var total = 0; for (var property in list) { if (list.hasOwnProperty(property)) { total = (+(total) + +(getProduct(property).price * list[property])).toFixed(4); } } var answ = confirm("total to pay: " + total + " eth"); if (!answ) { return; } axios.post('/api/purchase', { list: list }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); }