Array类型传送门:
转换方法(转换为字符串显示)
查看数组里面的值,可以调用toString()或valueOf()方法转换为字符串显示,默认为每个字符串之间以逗号分隔,也可以直接输出对象数组名进行查看
栈方法
- 栈是LIFO(Last-In-First-Out 后进先出)的数据结构,最新添加的项最早被移除
- push()方法从栈顶推入数据,pop()方法从栈顶移除数据
- push():可接收任意数量的参数,添加到数组末尾,返回的是修改后的数组长度
- pop():只能从数组末尾移除最后一项,减少length值,返回此移除的项
var colors = new Array();
alert(colors.push("red","blue")); //2
alert(colors); //red,blue
alert(colors.push("green")); //3
alert(colors); //red,blue,green
alert(colors.pop()); //green
alert(colors); //red,blue
alert(colors.length); //2
队列方法
- 队列是FIFO(First-In-First-Out 先进先出)的数据结构
- push()方法从末端添加数据
- shift()方法从前端去除一个数据,减少length值,并返回该项
var colors = new Array();
alert(colors.push("red","blue")); //2
alert(colors); //red,blue
alert(colors.push("green")); //3
alert(colors); //red,blue,green
alert(colors.shift()); //red
alert(colors); //blue,green
alert(colors.length); //2
unshift()与pop()方法
- 从相反的方向模拟队列
- unshift()方法从前端添加任意项,并返回数组长度
var colors = new Array();
alert(colors.unshift("red","blue")); //2
alert(colors); //red,blue
alert(colors.unshift("green")); //3
alert(colors); //green,red,blue
alert(colors.pop()); //blue
alert(colors); //green,red
总结
用于添加和删除数组项可以使用的方法:
数组前端添加:unshift() 前端删除:shift()末端添加: push() 末端删除:pop()