In this tutorial, we will learn about how to use and when to use the Reduce method in JavaScript.

What is Reduce method?

The reduce() method reduces all array elements down to one single value

The return value of the function is stored in an accumulator(total/result).

Note: This method does not change the original array.

Syntax

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

For Example, 

Suppose we have an array as follows:

let arr = [44,54,25,56];

Now we want to count the total amount from the above array, we can do this using reduce method as follows:

let total = arr.reduce(function (acc, cur, i, arr) {
  return acc + cur;
 }, 0);

console.log(total);//179

Topics covered:

Found this article helpful?

TutsCoder tutorials are free and ad-light — supported by readers like you. Buy me a coffee (or two ☕☕) as a token of appreciation and help keep Angular & Node.js content coming!

One-time. No subscription. 100% optional. 🙏 Every coffee counts!

Leave a Comment

Your email will not be published. Spam-free zone. ✌️

Available for Projects

Need Help With Your
Angular or Node.js Project?

7+ years of MEAN Stack experience. I build scalable Angular 21 apps, Node.js APIs, and SaaS products — delivered on time, every time.

7+ Years MEAN Stack Angular 21 + Nx Expert 20+ Projects Delivered Remote / Freelance