Let's use a loop to find the sum of the array elements.
let arr = [1, 2, 3, 4, 5];
let res = 0;
for (let elem of arr) {
res += elem;
}
console.log(res); // the required sum
Given an array:
let arr = [2, 5, 9, 3, 1, 4];
Find the sum of the array elements.
Given an array:
let arr = [2, 5, 9, 3, 1, 4];
Find the sum of elements that are even numbers.
Given an array:
let arr = [2, 5, 9, 3, 1, 4];
Find the sum of the squares of the array elements.
Given an array:
let arr = [2, 5, 9, 3, 1, 4];
Find the product of the array elements.