xxxxxxxxxx
<!DOCTYPE html>
<html>
<title>JavaScript 数组方法push()使用示例 - 基础教程(div.cn)</title>
<body>
<h1>数组 push() 方法</h1>
<p>单击按钮可将三个元素添加到数组:</p>
<button onclick="myFunc()">增加</button>
<p id="result"></p>
<script>
var fruits = ["Banana", "Mango", "Apple"];
document.getElementById("result").innerHTML = fruits;
function myFunc() {
var total = fruits.push("Strawberry", "Lychee", "Guava");
document.getElementById("result").innerHTML = fruits + "<br> Lenght = " + total;
}
</script>
</body>
</html>