Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to calculate average of array in javascript

const arrAvg = arr => arr.reduce((a,b) => a + b, 0) / arr.length
Comment

average function for javascript

function avg(arr){
	let additions = 0;
	for(let index=0; index<arr.length; index++){
    	additions += arr[index];
    }
    return (additions/arr.length);
}
Comment

javascript find average of numbers

const average = (...args) => args.reduce((a, b) => a + b) / args.length;

average(1, 2, 3, 4);
// Result: 2.5
Comment

calculate average javascript

var sum = array.reduce((a, b) => a + b, 0);	//get sum of all elements in array
var avg = (sum / array.length) || 0; //get average of all elements in array ;)
Comment

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}.`);
Comment

average javascript

let output = []

  
  for(let i = 0; i < input[0].length; i++)
  {
    let firstName = input[0][i];
    let lastName = input[1][i];
    let dateBirth = input[2][i];
    if(dateBirth < 10)
    {
      dateBirth = `0${dateBirth}`;
    }
    let birthMonth = `${input[3][i][0]}${input[3][i][1]}${input[3][i][2]}`
    let birth = `${dateBirth}/${birthMonth}/${input[4][i]}`
    let age = 2021 - input[4][i]
    output.push(`${firstName} ${lastName} - ${birth} - ${age} Tahun`)
  }
  return output;
}
Comment

JavaScript average function

const arr = [5,10,15,20,25];
        arr.reduce(function(x,y){
            sum = x+y;
            mean = sum/arr.length;
            return sum;
        },
        0);
         console.log(mean);//15
Comment

PREVIOUS NEXT
Code Example
Javascript :: what is virtual dom in react 
Javascript :: js create array with default value 
Javascript :: vue mapgetters with parameter 
Javascript :: check Browser version js 
Javascript :: javascript date to string format dd mmm yyyy 
Javascript :: js class exists 
Javascript :: jszip angular 
Javascript :: jquery display text in div 
Javascript :: how to add number in string in javascript 
Javascript :: linking html with javascript 
Javascript :: set input value vanilla js 
Javascript :: using async function in useeffect 
Javascript :: how to hide ascending descending icons in datatable js 
Javascript :: variable for every user discord.js 
Javascript :: deduplicate array javascript 
Javascript :: react native paper modal background 
Javascript :: jsonwebtoken error with react js 
Javascript :: how to convert jsonobject to string in java 
Javascript :: fetch js 
Javascript :: discord.js guildMemberRemove 
Javascript :: remove repetition 2d array javascript 
Javascript :: html escape function javascript 
Javascript :: create object javascript dynamically 
Javascript :: how to change background image dynamically in react 
Javascript :: map list in javascript 
Javascript :: regex data 
Javascript :: get current html file name javascript 
Javascript :: grayscale image in canvas 
Javascript :: higher order function in javascript 
Javascript :: replace each string by another string javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =