How to add together an array of numbers in javascript? -


I have to take an array of 12 numbers and call them together by joining together a function and get the average of the numbers and the second To get the total number of numbers.

My array looks like this:

  monthly sales [0] = 30000; Monthly sales [1] = 10000; Monthly sales [2] = 15000; Monthly sales [3] = 20000; Monthly sales [4] = 20000; Monthly sales [5] = 25000; Monthly sales [6] = 22000; Monthly sales [7] = 80000; Monthly sales [8] = 20000; Monthly sales [9] = 20000; Monthly sales [10] = 40000; Monthly sales [11] = 60000;   

I have to use it in some way to get array values:

  seenUpMonthlySales = selectedIndex monthlySales [selectedIndex]   

> I am not sure how to get the values ​​of arrays in my other two functions from the array and how to get them together and get their average.

According to the comment request ... it explains how to ask in the question. To get a function and average to add elements, a function is assumed that the array provided is in the form of states.

  function addUp (monthlys) {var xx, totalOfArray; {TotalOfArray = totalOfArray + monthly sales [xx] for (xx = 0; xx; lt; 12; xx ++); } Total Return OFF; } Function average (total ISM, AMS) {var averageoffer = total I / Ams; Return averageofferre; } // To know the sum of the elements in the array: var totalIs = addUp (monthlySales); // To find average: var averageIs = averageOf (totalIs, 12); Warning (averageIs);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -