# Sum and Product of Array elements using JavaScript

Given an array and is the task to find the Sum and Product of the values of an Array using JavaScript.

Simple method: It uses a simple method to access the array elements by an index number and use the loop to find the sum and product of values of an Array using JavaScript.

Example 1: This example uses a simple method to find the sum of Array elements using JavaScript.

                 How to Find the sum of Values         of an Array in JavaScript?

GeeksForGeeks

How to Find the sum of Values         of an Array in JavaScript?

----Given Array----
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Output:

• Before click on the Button:
• After Click on the Button:
• Example 2: This example uses a simple method to find the product of Array elements using JavaScript.

                 How to Find the product of Values         of an Array in JavaScript?

GeeksForGeeks

How to Find the product of Values         of an Array in JavaScript?

----Given Array----
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Output:

• Before click on the Button:
• After Click on the Button:

Using reduce() method: The array reduce() method in JavaScript is used to reduce the array to a single value and executes a provided function for each value of the array (from left-to-right) and the return value of the function is stored in an accumulator.

Syntax:

array.reduce( function( total, currentValue, currentIndex, arr ), initialValue )

Example 1: This example uses array reduce() method to find the sum of values of an Array using JavaScript.

                 How to Find the sum of Values         of an Array in JavaScript?

GeeksForGeeks

How to Find the sum of Values         of an Array in JavaScript?

----Given Array----
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Sum:

Output:

• Before click on the Button:
• After Click on the Button:

Example 2: This example uses array reduce() method to find the product of values of an Array using JavaScript.

                 How to Find the product of Values         of an Array in JavaScript?

GeeksForGeeks

How to Find the product of Values         of an Array in JavaScript?

----Given Array----
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

Product:

Output:

• Before click on the Button:
• After Click on the Button:

My Personal Notes arrow_drop_up

Small things always make you to think big

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.