W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 数组</h1> <p>forEach() 方法按顺序为数组中的每个元素调用一次函数。</p> <p id="demo"></p> <script> let text = ""; const fruits = ["apple", "orange", "cherry"]; fruits.forEach(myFunction); document.getElementById("demo").innerHTML = text; function myFunction(item, index) { text += index + ": " + item + "<br>"; } </script> </body> </html>