源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>push 方法返回新数组长度.</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> var fruits = ["Banana", "Orange", "Apple", "Mango"]; document.getElementById("demo").innerHTML = fruits; function myFunction() { document.getElementById("demo").innerHTML = fruits.push("Kiwi"); } </script> </body> </html>
运行结果