I have the following values in an array which I am trying to get the sum of it. This is how it looks like from the chrome developer tools
(3) [{…}, {…}, {…}]0: {ID: 1, ProductName: " New phone 1", Price: "€ 600"}1: {ID: 3, ProductName: " New phone 2", Price: "€ 1000"}2: {ID: 4, ProductName: " New phone 3", Price: "€ 400"}length: 3__proto__: Array(0)
I would like to get the prices of each Item and compute a sum of all the values. I getting these values from an Api and it could sometimes be more items or less. Currently this is how I am getting the values
function setTotalPrice() {
fetch("http://localhost:1234/api/Product")
.then(response=>response.json())
.then(data => {
data.forEach(element => {
console.log(element.Price)
});
})
}