遍历数组
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 数组</h1>
- <p>遍历数组的最佳方法是使用标准的 for 循环:</p>
- <p id="demo"></p>
- <script>
- var fruits, text, fLen, i;
- fruits = ["Banana", "Orange", "Apple", "Mango"];
- fLen = fruits.length;
- text = "<ul>";
- for (i = 0; i < fLen; i++) {
- text += "<li>" + fruits[i] + "</li>";
- }
- text += "</ul>";
- document.getElementById("demo").innerHTML = text;
- </script>
- </body>
- </html>