Been finding the this sum difficult to solve:
Question: Given an array of integers, find the sum of its elements.
For example, if the array ar = [1,2.3],1+2+3=6 so return 6.
Function Description
Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.
I have tried:
function simpleArraySum(ar) {
    var sum = 0;
    for (var i = 0; i <ar.length; i++) {
    sum += (ar);
    return sum;
    }
}
Output is: 01,2,3,4,10,11
It should be 31.
Help please



sum += (ar)supposed to do?sumis a number andaran array. And why isreturn sumin the loop?sum += (ar);tries to add the arrayartosum. You have to access the individual elements of the array instead (that's why you are using a loop).return sum;inside the loop will terminate the function (and therefore the loop) in the first iteration of the loop. Only return the sum after you have processed all array elements.arr.reduce((a,v) => a + v ,0)