<script type="text/javascript">
var newObject=new Array("red","green","blue");
document.write(newObject); //output red,green,blue
//Array拥有栈结构的特征
newObject.pop();
document.write("<br>"+newObject); //output red,green
newObject.push("new color");
document.write("<br>"+newObject); //output red,green,new color
/*test the method shift() and unshift();
shift()删除数组的第一项,并返回删除的元素值;由shift()和push()方法可以构成类似队列结构的功能。
unshift()添加某个元素到数组的第一项,其他原本元素向下推移。
*/
var test=newObject.shift();
document.write("<br>"+newObject); //output green,new color
newObject.unshift("pink");
document.write("<br>"+newObject); //output pink,green,new color
</script>
javascript Array类 学习
最新推荐文章于 2024-04-20 12:08:31 发布