Array.every()

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript Array.every()</h1>
  6.  
  7. <p>every() 方法检查所有数组值是否通过测试。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var numbers = [45, 4, 9, 16, 25];
  13. var allOver18 = numbers.every(myFunction);
  14.  
  15. document.getElementById("demo").innerHTML = "所有大于 18 的是:" + allOver18;
  16.  
  17. function myFunction(value, index, array) {
  18. return value > 18;
  19. }
  20. </script>
  21.  
  22. </body>
  23. </html>