javascript reduce system es6
Reduces and maps, like filters, but it takes more than one argument. We know the stat variables in the programming world.
Its job is to count something or to detect it during an operation. Simply put, if we want to find the total of all the numbers in an array, then we can easily reduce it using Reduce.
Get Digital.Press’s stories in your inbox
Join Medium for free to get updates from this writer.
Since Reduce has stat variables, this may be the perfect choice for such an operation.
Hold the array
const arr = [1, 2, 3, 4,5]
I want to know the total of all items. If you apply Reduce
const total = arr.reduce(function(sum, item){
return sum += item;
}, 0);
Result
console.log(total) // 15









