JavaScript使用pop方法移除数组最后一个元素用法实例
2015-04-08来源:易贤网

下面的代码演示了JS数组的pop方法,可以用来移除数组的最后一个元素,实际上就是把数组当成堆栈使用

<!DOCTYPE html>

<html>

<body>

<p id="demo">

Click the button to remove the last array element.

</p>

<button onclick="myFunction()">Try it</button>

<script>

var fruits = ["Banana","Orange","Apple","Mango"];

function myFunction()

{

fruits.pop();

var x=document.getElementById("demo");

x.innerHTML=fruits;

}

</script>

</body>

</html>

运行结果如下:

Banana,Orange,Apple

更多信息请查看IT技术专栏

2025公考·省考培训课程试听预约报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息