JavaScript push()方法

定义: 使用push()方法可以向数组的末尾添加一个或多个元素并且返回新的长度 。

语法: arrayObject.push(newelement1,newelement2,....,newelementX)

Parameter 参数                                             Description描述

 

newelement1                                                Required. The first element to add to the array 必要选项。向数组添加的第一个元素

newelement2                                                 Optional. The second element to add to the array 可选项。向数组添加的第二个元素

newelementX                                                Optional. Several elements may be added 可选项。可添加多个元素

 

注意: 要向数组的头部加入一个或多个元素,可以使用unshift()方法。 示例: Js代码

 

Js代码
<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.push("Kai Jim") + "<br />")
document.write(arr)
</script>

posted @ 2010-11-29 20:21  稍侯..。纠结  阅读(832)  评论(0)    收藏  举报