Reduce Method Example in JavaScript
The reduce() method executes a reducer function for array element.
The reduce() method returns a single value: the function's accumulated result.
Get Chamod Dilshan πβs stories inΒ yourΒ inbox
Join Medium for free to get updates fromΒ thisΒ writer.
The reduce() method does not execute the function for empty array elements.
The reduce() method does not change the original array.
const prices = [2, 4, 52, 75, 45, 43];
const total = prices.reduce(sum);
console.log(total)
function sum(previous, next){
return previous + next;
}








