W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 数组</h1> <p>Array.forEach() 为每个数组元素调用函数。</p> <p>Internet Explorer 8 以及更早的版本不支持 Array.forEach()。</p> <p id="demo"></p> <script> var fruits, text; fruits = ["Banana", "Orange", "Apple", "Mango"]; text = "<ul>"; fruits.forEach(myFunction); text += "</ul>"; document.getElementById("demo").innerHTML = text; function myFunction(value) { text += "<li>" + value + "</li>"; } </script> </body> </html>