1 //splice(起始位置,要删除的个数,要插入的数据)
2 var colors = ["red", "green", "blue"];
3 var removed = colors.splice(0, 1);
4 console.log(colors);
5 console.log(removed);
6
7 removed = colors.splice(1, 0, "yellow", "orange");
8 console.log(colors);
9 console.log(removed);
10
11 removed = colors.splice(1, 1, "red", "purple");
12 console.log(colors);
13 console.log(removed);
2 var colors = ["red", "green", "blue"];
3 var removed = colors.splice(0, 1);
4 console.log(colors);
5 console.log(removed);
6
7 removed = colors.splice(1, 0, "yellow", "orange");
8 console.log(colors);
9 console.log(removed);
10
11 removed = colors.splice(1, 1, "red", "purple");
12 console.log(colors);
13 console.log(removed);
不知道为什么chrome下的console.log取到的值竟然和IE、Firefox不同。感觉是全局变量的问题,变量输出以后重新定义前木有删除前一次的值。alert下取值都相等。