Answers for "javascript get average from array"

CSS
8

how to calculate average of array in javascript

const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length
Posted by: Guest on March-23-2020
3

javascript average of numbers in array

const scores = [ 20, 50, 75, 100, 115 ];
let total = 0;

for ( let i = 0; i < scores.length; i++ ) {
  total += scores[i];
}

console.log( total / scores.length );
Posted by: Guest on September-05-2021
0

javascript calculate average of array

const sum = times.reduce((a, b) => a + b, 0);
const avg = (sum / times.length) || 0;

console.log(`The sum is: ${sum}. The average is: ${avg}.`);
Posted by: Guest on December-01-2021

Browse Popular Code Answers by Language