运行 ❯
获取您
的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <h2>The every() Method</h2> <p>The every() method returns true if every element in an array pass a function test.</p> <p>Click the button to check if every element in the array has a value above this number:</p> <p><input type="number" id="ageToCheck" value="18"></p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> // Create an Array const ages = [32, 33, 12, 40]; // Create a Test Function function checkAge(age) { return age > document.getElementById("ageToCheck").value; } // Displau check result function myFunction() { document.getElementById("demo").innerHTML = ages.every(checkAge); } </script> </body> </html>