运行 ❯
获取您的
自有
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往空间
<!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <h2>The length Property</h2> <p>The length property provides an easy way to append new elements to an array without using the push() method:</p> <p id="demo1"></p> <p id="demo2"></p> <script> const fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo1").innerHTML = fruits; fruits[fruits.length] = "Kiwi"; document.getElementById("demo2").innerHTML = fruits; </script> </body> </html>