Home > Article > Web Front-end > How to find the sum of even numbers in javascript
How to find the sum of even numbers in JavaScript: First open the corresponding code file; then pass "for(i = 0;i
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to find the sum of even numbers in javascript?
Finding the sum of even numbers in js
The code is as follows:
<script> var sum =[52,58,79,46,13,52,68,45] document.write(sum.sort()+"<hr>"); var num = 0; for(i = 0;i<sum.length;i++){ if(sum[i]%2 ==0){ num+=sum[i] } } document.write("偶数和为"+num) </script>
Recommended study: "javascript Advanced Tutorial"
The above is the detailed content of How to find the sum of even numbers in javascript. For more information, please follow other related articles on the PHP Chinese website!