W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 数组</h1> <p>添加具有高索引的元素可以在数组中创建未定义的“孔”。</p> <p id="demo"></p> <script> var fruits, text, fLen, i; fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits[6] = "Lemon"; fLen = fruits.length; text = ""; for (i = 0; i < fLen; i++) { text += fruits[i] + "<br>"; } document.getElementById("demo").innerHTML = text; </script> </body> </html>