I have read other question regarding to for-of loop and came up with this code calculating average and summ of all elements in array, there seems to be something incorrect, help would be appreciated.:
var i;
elmt=[]
elmt[0] = 0;
elmt[1] = 1;
elmt[2] = 2;
elmt[3] = 3;
elmt[4] = 4;
elmt[5] = 7;
elmt[6] = 8;
elmt[7] = 9;
elmt[8] = 10;
elmt[9] = 11;
var sum = 0;
for (let sum of elmt) {
sum += parseInt( elmt[i], 10 );
}
var avg = sum/elmt.length;
document.write( "The sum of all the elements is: " + sum + " The average is: " + avg );
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Loops</h2>
<p id="demo"></p>
</body>
</html>
If you guys know other easier way doing the same thing using 'for-of' loop feel free to share.