Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
how to loop through a list of object to find total value

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.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try:

const items = [{"_id":"61d167f9f5986df9dd291603","name":"test2","price":2000},{"_id":"61d167f9f5986df9dd291602","name":"test3","price":4000},{"_id":"61d167f9f5986df9dd291601","name":"test4","price":5000}];

let total = 0;
for(let i = 0; i <= items.length - 1; i++) {
    total += items[i].price
}
console.log(total)

about 4 years ago · Juan Pablo Isaza Report

0

Fetch this JSOn data into the List / ArrayList and using the for each loop traverse that list using object. Example - Suppose your data is stored in list whose object name is data int total = 0 for each list_data_type in data1 total = data1.price + total;

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!