Array.every()
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript Array.every()</h1>
- <p>every() 方法检查所有数组值是否通过测试。</p>
- <p id="demo"></p>
- <script>
- var numbers = [45, 4, 9, 16, 25];
- var allOver18 = numbers.every(myFunction);
- document.getElementById("demo").innerHTML = "所有大于 18 的是:" + allOver18;
- function myFunction(value, index, array) {
- return value > 18;
- }
- </script>
- </body>
- </html>