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

171
Views
JS For-Loop through objects' keys in an array

I have an array like this:

const list = [
    {
      quantity: 100,
      cost: 100,
      fee: 100,
    },
    {
      quantity: 200,
      cost: 200,
      fee: 200,
    },
    {
      quantity: 300,
      cost: 300,
      fee: 300,
    },
  ];

I would like to make a function that loops through it to get the total of each object's key like this:

  const cal = (item) => {
    let total = 0;
    for (let i = 0; i < list.length; i++) {
      total = list[i].item + total;
    }
    return total;
  };

So that I could run something like this:

console.log(cal(quantity));
console.log(cal(cost));
console.log(cal(fee));

Is the a way to achieve this please? I appreciate it!

about 4 years ago · Juan Pablo Isaza
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!