Languages
[Edit]
EN

JavaScirpt - average value using array reduce()

0 points
Created by:
Dirask Community
5610

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

In below example, we pass an arrow function calculating the average value of numbers to thereduce() method.

Runnable example:

// ONLINE-RUNNER:browser;

const numbers = [10, 20];

function average(array) {
    return array.reduce((a, b) => (a + b)) / array.length;
}

console.log(average(numbers)); //15

References

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.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join