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