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>findIndex()</h2> <p>findIndex() returns the index of the first element that passes a test (provided by a function).</p> <p id="demo"></p> <script> const ages = [3, 10, 18, 20]; document.getElementById("demo").innerHTML = ages.findIndex(checkAge); function checkAge(age) { return age > 18; } </script> <p>findIndex() is not supported in Internet Explorer.</p> </body> </html>