<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script> //将数组中的所有元素相加,求和 var arr=[12,56,89,12,0.5,4.9,18]; var n=0; for(var i=0;i<arr.length;i++){ n+=arr[i] } console.log(n) </script> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <script> //将数组中的所有元素相加,求和 var arr=[12,56,89,12,0.5,4.9,18]; var n=0; for(var i=0;i<arr.length;i++){ n+=arr[i] } console.log(n) </script> </body> </html>