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

JavaScript
JS 字符串
JS Date
JS数组,JS Array
JS Boolean
JS Math
JS HTML DOM
JS Browser
JS Cookies
JS 校验
JS Animation
JS Image Maps
JS Timing
JS 建立对象
JS 摘要
JS 实例
JS 对象实例
JS DOM 实例
JS数组对象参考
JS布尔对象参考
JS日期对象参考

JavaScript shift()方法


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

Definition and Usage
定义于用法

The shift() method is used to remove and return the first element of an array.
shift()方法可用来删除数组第一个元素并且返回它的值。

Syntax
语法

arrayObject.shift()


Tips and Notes
提示与注意点

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

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


Example
举例

In this example we will create an array, and then remove the first 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.shift() + "<br />")
document.write(arr)
</script>

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

Jani,Hege,Stale
Jani
Hege,Stale


Try-It-Yourself Demos
尝试与演示

shift()
How to use shift() to remove and return the first element of an array.
如何使用shift()来删除和返回数组的第一个元素

评论 (0) All

登陆 | 还没注册?