# How to get the sum of numbers in an array javascript?

**Question: how to get sum of array in javascript?, How to get total sum array js?, using map reduce prototype developers, total js, javascript sum array, acc web development or many more..**

Today, We want to share with you **Calculate the sum of values in an array**.In this post we will show you ** JavaScript GROUP BY Function With Example**, hear for

*two ways to find the reduced of an array of numbers Example by using JavaScript.*we will give you demo and example for implement.In this post, we will learn about

*what does reduce mean in math*with an example.

## First way using for of loop.

In the below source code, I have used for of loop to get or find the number any numeric directly instead of index.here example to 1 2 3 4 5 reducer of array elements in javascript

**On for loop each iteration, I have more added the number to sum of total js variable.**

let sum_array = [1,2,3,4,5]; let total_js = 0; for (let num of sum_array){ total_js = total_js + num } console.log(total_js) // 15

## Array.reduce( ) method

There is an inbuilt reduce method in pure JavaScript which needs to total js calculate the sum of all the map reduce numbers in the array.

**Syntax of reduce in JavaScript**

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

**reduce examples**

let sum_array = [1,2,3,4,5]; const total_js = sum_array.reduce((result,number)=> result+number); console.log(total_js) // 15

In the above all the js source code on each loop to iteration reducer function save or store, the total numbers sum of all total js value inside the result parameter as well as last step to finally returns the result value.

simple map reduce() method takes the pure javascript callback function as its single parameter as well as executes that callback function on each data DOM element present in the js array.

The javascript callback function takes default two parameters result with new fresh current element.

##### Web Programming Tutorials Example with Demo

### Read :

### Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about **javascript sum array of objects**.

I would like to have feedback on my infinityknow.com blog.

Your valuable feedback, question, or comments about this article are always welcome.

If you enjoyed and liked this post, don’t forget to share.

## Related FAQ

Here are some more FAQ related to this Article: