Sitemap
Chamod Dilshan 😎

Chamod Dilshan 😎

I'm Chamod Dilshan! πŸš€ Entrepreneur πŸš€ ICT undergrad, web dev, and tech enthusiast. Wordsmith on the side. Let's explore tech together

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;
}

--

--

Chamod Dilshan 😎
Chamod Dilshan 😎

Written by Chamod Dilshan 😎

I'm Chamod Dilshan! πŸš€ Entrepreneur πŸš€ ICT undergrad, web dev, and tech enthusiast. Wordsmith on the side. Let's explore tech together