var a = new Array();
a.unshift("red", "green");
a.unshift("black");
这个时候a数组中的顺序是这样的
a[0]="black" a[1] = "red" a[2]="green"
记住unshift()中传入多个参数时,先把最后一个参数推入数组,unshift()是在数组头部添加数据,(新填入的数据用红色字体标出)
如a.unshift("red", "green","black");先把black推入数组a,再把green推入数组a,再把red推入数组a
第一步:1.a[0] = "black"
第二步:2.a[0] = "green" a[1] = "black"
第三步:3.a[0] = "red" a[1] = "green" a[2] = "black";
而a.push("red","green","black");先把第一个参数放入数组,push()是在尾部添加
如a.push("red","green")
第一步:1.a[0] = "red"
第二步:2.a[0] = "red" a[1] = "green"
第三步:3.a[0] = "red" a[1] = "green" a[2] = "black";