I have a list of objects and I need to loop through each object add all the "price" field to get the total value.
[
{
"_id":"61d167f9f5986df9dd291603",
"name":"test2",
"price":2000
},
{
"_id":"61d167f9f5986df9dd291602",
"name":"test3",
"price":4000
},
{
"_id":"61d167f9f5986df9dd291601",
"name":"test4",
"price":5000
}
]
I tried doing,
for(i in items){
let total = total + i.price;
}
console.log(total)
But dint work.