reduce() is used to convert an array into a single value.
array.reduce((accumulator, currentValue) => {
}, initialValue);
accumulator → stores previous result
currentValue → current array item
initialValue → starting value
Example
1. Sum of Array
const numbers = [10, 20, 30, 40];
const total = numbers.reduce((sum, current) => {
return sum + current;
}, 0);
console.log(total); // 100


