js数组之从数组中删除元素

使用pop()这个函数可以从数组中删除末尾的元素,shift方法可以删除数组中第一个元素。这些都是js中自带的函数,如果不使用这些函数的话,自己写的代码效率会很低的。

    

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


	function B(){
		var names1=["zhangsan1","lisi1","wangwu1"];
		names1.pop();
		names1.shift();
		
		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:18  airycode  阅读(546)  评论(0编辑  收藏  举报

导航