I am trying to iterate over an array of objects instead its returning only one item here is the code:
setAll(){
var result =this.cart;
for (var key in result) {
var obj = result[key];
}
return obj.price;
}
and the test data
[ { "id": 5, "price": 3200, "quantity": 8, "name": "juice" }, { "id": 6,
"price": 300, "quantity": 6, "name": "rice" }, { "id": 8, "price": "100",
"quantity": 1, "name": "water" }, { "id": 7, "price": "4500", "quantity":
1, "name": "meat" } ]
[3200, 300, 100, 4500]?prices = cart.map(({price}) => +price);to get all prices from thecartarray.