//求数组的元素和
1 var arr = [2,6,1,7,4];
2
3 var num = 0;
4 for(var i = 0;i < arr.length;i++){
5 console.log(arr[i]);
6 var num = num + Number(arr[i]);
7 }
8 console.log(num);
////////将1~10存到数组里面
1 var arr = [];
2 for (var i = 0;i < 10;i++){
3 arr[i] = i + 1;
4 }
5 console.log(arr);
//在一个数组中挑选出大于10的数字放到另外的数组中
1 var oldarr = [2.5,7,11,8,22,33,6,66];
2 var newarr = [];
3 var j = 0;
4 for (var i = 0;i < oldarr.length;i++){
5 if (oldarr[i] > 10){
6 newarr[j] = oldarr[i];
7 j++;
8 }
9 }
10 console.log(newarr);
//找出数组中最大值的案例
1 var max = 0;
2 var arr = [2,6,1,77,52,25,7];
3 var max = arr[0];
4 for(var i = 1;i <= arr.length;i++){
5
6 if(arr[i] > max){
7 max = arr[i];
8 }
9 }
10 console.log(max);