0

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

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.