In this program, we need to calculate the sum of all the elements of an array. This can be solved by looping through the array and adding the value of the element in each iteration to the variable sum.
PROGRAM :
// Given Array
let array=[1,2,3,4,5,6];
// Storing length of array
let n=array.length;
let sum=0;
for(let i=0;i<n;i++){
sum=sum+array[i];
}
console.log("Sum of given array is",sum)