Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <h2>The find() Method</h2> <p>Click "Test" to return the value of the last element in the array that has a value above this number:</p> <p><input type="number" id="ageToCheck" value="18"></p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> const ages = [4, 12, 16, 20]; function checkAge(age) { return age > document.getElementById("ageToCheck").value; } function myFunction() { document.getElementById("demo").innerHTML = ages.findLast(checkAge); } </script> </body> </html>