当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript pop()方法

JavaScript
JS 介绍
JS 怎样使用
JS 在哪使用
JS 变量
JS If...Else
JS Switch
JS 操作符
JS Popup Boxes
JS 函数
JS For 循环
JS While 循环
JS Break 循环
JS For...In
JS 事件
JS Try...Catch
JS Throw
JS onerror
JS 特殊字符
JS Guidelines
JS 对象介绍

JavaScript pop()方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 328 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

The pop() method is used to remove and return the last element of an array.
pop()方法可用来删除和返回数组中最后的一个元素

Syntax
语法

arrayObject.pop()


Tips and Notes
提示与注意点

Note: This method changes the length of the array.
注意:这个方法会改变数组的长度

Tip: To remove and return the first element of an array, use the shift() method.
提示:如要删除并返回数组的第一个元素,可以使用shift()方法


Example
举例

In this example we will create an array, and then remove the last element of the array. Note that this will also change the length of the array:
这个举例中我们将会建立一个数组,接着我们会删除该数组的最后一个元素。注意,同时还会改变原有数组的长度:

<script type="text/javascript">
var arr = new Array(3)
arr[0] = "Jani"
arr[1] = "Hege"
arr[2] = "Stale"
document.write(arr + "<br />")
document.write(arr.pop() + "<br />")
document.write(arr)
</script>

The output of the code above will be:
上面代码的输出结果为:

Jani,Hege,Stale
Stale
Jani,Hege


Try-It-Yourself Demos
尝试与演示

pop()
How to use pop() to remove and return the last element of an array.
怎样使用pop()删除并返回数组中的最后一个元素。

评论 (0) All

登陆 | 还没注册?