Defines an array of 30 integer elements, giving an even number starting from 2 in order, then averaging each of the five numbers in order, placing them in another array and outputting

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script type= "Text/javascript" >
Defines an array of 30 integer elements, giving an even number starting from 2 in order, and then averaging each of the five numbers in order, placing them in another array and outputting them.
var arr = [];
var NewArr = [];
var average = 0;
Arr.length = 30;
for (var i = 1; I <= arr.length; i++)
{
Arr[i-1] = 2*i;
Assign arr Arr[i-1] because the array subscript starts at 0

if (i% 5!== 0)
Make a judgment of the five numbers as a group and then put the average of each group into another array
{
Average + = arr[i-1];
}else
{
Newarr.push (AVERAGE/5);
Average = 0;
}
}
Console.log (arr);
Console.log (NEWARR);
</script>
<body>
</body>

Defines an array of 30 integer elements, giving an even number starting from 2 in order, then averaging each of the five numbers in order, placing them in another array and outputting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.