W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h2>JavaScript Array.forEach()</h2> <p>为每个数组元素调用一次函数。</p> <p id="demo"></p> <script> const numbers = [45, 4, 9, 16, 25]; let txt = ""; numbers.forEach(myFunction); document.getElementById("demo").innerHTML = txt; function myFunction(value) { txt += value + "<br>"; } </script> </body> </html>