js数组之可变函数

  在js的数组中有两个方法为数组添加元素:1.push();2.unshift(),push函数是将元素添加到数组的末尾,现在不用说大家估计也能猜出来,unshift这个函数就是把元素添加到数组的开头的位置上。

  上代码:

          

<html>
<head>
	<title>数组的字符串表示</title>
	<script type="text/javascript">
	


	function B(){
		var names1=["zhangsan1","lisi1","wangwu1"];
		names1.push("lily1");
		names1.unshift("lily2");
		
		alert(names1);

	}

	</script>
</head>
<body>
<input type="text" name="name" id="name">
<input type="button" value="dian" onclick="B();">

</body>
</html>

  

posted on 2015-09-18 17:13  airycode  阅读(924)  评论(0编辑  收藏  举报

导航