Array.findIndex()
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript Array.findIndex()</h1>
- <p id="demo"></p>
- <script>
- var numbers = [4, 9, 16, 25, 29];
- var first = numbers.findIndex(myFunction);
- document.getElementById("demo").innerHTML = "大于 18 的第一个值的索引是:" + first;
- function myFunction(value, index, array) {
- return value > 18;
- }
- </script>
- </body>
- </html>