1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>求一个数组内的所有数字的和</title> 6 </head> 7 <body> 8 <script> 9 function addUp(Arr){ 10 var total=0; 11 for(var i=0; i<Arr.length;i++){ 12 total+=Arr[i]; 13 } 14 return total; 15 } 16 17 var myArr=[2,3,5,3,23,43,323,]; 18 var result=addUp(myArr); 19 console.log(result); 20 </script> 21 </body> 22 </html>