I wanted to calculate the average of the innermost arrays as mentioned below without using names of the properties. Is there a way out. I am using javascript. Currently using this syntax, i am getting the array is not defined.
average.js
var data=
[
{
"load":[1,2,3],
"network":[5,6,7]
},
{
"load":[10,11,12],
"network":[14,15,16]
}
]
// I want to calculate the average for each of the properties 'load','network' and many more....
function avg(i)
{
for(j=0;j<data[i].length;j++)
{
sum=0;
for(k=0;j<data[i][j].length;k++)
{
sum+=data[i][j][k];// it do not seems correct
}
average=sum/3;
document.write("value "+i+":"+average);//just for testing
}
}
average.html
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<script src="average.js"></script>
</head>
<body>
<script>
avg();
</script>
</body>
</html>