'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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source