Как сложить значения "price" полученные с сервера по API в файле JSON и отобразить общую сумму "price" в этом
<div class="summ"></div>
элементе?
async function postData(url = 'https://s-point.wb.ru/s6/api/v3/pickpoint/goods/list?filter.status=GOODS_READY') {
var myresponse = await fetch(url, {
method: 'GET',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
"Accept": ["application/json", "text/plain", "*/*"],
"x-token": 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzaWQiOiI0NjMxOmZkZTA4ZGE3OWNmOTYyYTUiLCJ1aWQiOjQ2MzEsInd1aWQiOjQ0NTc1MDMwLCJwaWQiOjIzNjYsInhwaWQiOjEyMTMwOSwicyI6NiwiciI6WzJdLCJhZG1pbiI6ZmFsc2UsImNvdW50cnkiOiJSVSIsImV4cCI6MTY1NjQ4NzY0MywiaWF0IjoxNjU1NjIzNjQzfQ.4TpDG3v6yqSD6h49Q-zpxnsePHqPxS8FDL'
},
});
if (myresponse.ok)
var json = await myresponse.json()
//var json = JSON.stringify(json.pickpoints);
return json;
}
postData()
.then((json) => {
if (json)
var pvzBalans = document.getElementById('mybalans');
if(!pvzBalans) {
pvzBalans = document.createElement("div");
pvzBalans.id = 'mybalans';
document.body.appendChild(pvzBalans);
}
pvzBalans.innerHTML = `<div class="summ"> ${'Сумма '+" "+ json.data[5].price +' '+ json.data[0].currency} </div>`;
console.log(pvzBalans);
console.log(json);
});
Файл JSON:
{
"data": [
{
"id": 85089504,
"model_code": 45676678,
"buyer": {
"user_id": 41225528,
},
"price": 164,
"info": {
"goods_size": "0",
"no_return": true,
"pics_cnt": 7,
"adult": false
},
"currency": "₽",
"need_trust_sign": false,
"trust_sign_equation": "",
"good_decline_claim": null,
"buyer_delivery_status": true,
"transfer_box_id": 0
},
{
"id": 85093937,
"model_code": 105925630,
"buyer": {
"user_id": 23129458,
},
"price": 222,
"info": {
"goods_size": "XXL",
"no_return": false,
"pics_cnt": 6,
"adult": false
}
],
}