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

162
Views
How to calculate sum of multiple responses inside a loop using javascript?

I have two loops as shown:

        for (var i = 0; i < nearPlacements.length; i++) {
           var meshInstances = nearPlacements[i].model.model.meshInstances;
var mat;
var matEach = 0;
for (var i2 = 0; i2 < meshInstances.length; i2++) {
    mat = parseFloat(meshInstances[i2].mesh.indexBuffer[0].numIndices / 3);
    matEach += mat;
    }
    console.log(matEach);
}

console.log(matEach); outputs data as:

enter image description here

How to display data as a sum of all responses? Thanks

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

0

its like what you did with matEach variable but outside outer loop.

let total = 0;
for (var i = 0; i < nearPlacements.length; i++) {
  var meshInstances = nearPlacements[i].model.model.meshInstances;
  var mat;
  var matEach = 0;
  for (var i2 = 0; i2 < meshInstances.length; i2++) {
    mat = parseFloat(meshInstances[i2].mesh.indexBuffer[0].numIndices / 3);
    matEach += mat;
  }
  console.log(matEach);
  total += matEach;
}

console.log(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!