1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 </head> 7 <body> 8 <script> 9 //将数组中的所有元素相加,求和 10 var arr=[12,56,89,12,0.5,4.9,18]; 11 var n=0; 12 for(var i=0;i<arr.length;i++){ 13 n+=arr[i] 14 } 15 console.log(n) 16 </script> 17 </body> 18 </html>标签:11,12,18,元素,数组,var From: https://www.cnblogs.com/webaction/p/16648134.html