在数组的头部添加元素
- 方法
arr.unshift(item1,item2,...,itemn);
- 例子
let arr1 = [1,2,3];
arr1.unshift(4,5,6);
结果:
[4, 5, 6, 1, 2, 3]
在数组的尾部添加元素
arr.push(item1,item2,...,itemn);
- 例子
let arr2 = [1,2,3];
arr2.push(4,5,6);
结果:
[1, 2, 3, 4, 5, 6]
arr.unshift(item1,item2,...,itemn);
let arr1 = [1,2,3];
arr1.unshift(4,5,6);
结果:
[4, 5, 6, 1, 2, 3]
arr.push(item1,item2,...,itemn);
let arr2 = [1,2,3];
arr2.push(4,5,6);
结果:
[1, 2, 3, 4, 5, 6]