搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
JavaScript 教程
JavaScript基础教程
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>JavaScript for遍历数组示例 - 基础教程(div.cn)</title> <body> <h2> JavaScript数组</h2> <p>单击按钮以遍历数组:</p> <button onclick="myFunc()">Click</button> <p id="result"></p> <script> function myFunc() { let fruits = ["Apple", "Mango", "Banana", "Orange"]; let txt = ""; // Loop through the length of the array for (let i = 0; i < fruits.length; i++) { txt += i + " = " + fruits[i] + "<br>"; } document.getElementById("result").innerHTML = txt; } </script> </body> </html>
运行结果