JavaScript - average value calculation using array reduce()

3 points
Created by:

In this article, we would like to show you how to calculate the average value with reduce() method in JavaScript.

Runnable example:

// ONLINE-RUNNER:browser;

const calculateAverage = (array) => {
    const sum = array.reduce((a, b) => a + b);
    return sum / array.length;

// Usage example:

const numbers = [10, 20, 30];
const average = calculateAverage(numbers);

console.log(average);  // 20

See also

  1. JavaScript - average value calculation

  2. JavaScript - weighted arithmetic mean

  3. JavaScript - moving average


Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂