数组
不改变原数组:
- concat
- forEach
- every 返回true或false
- some 返回true或false
- reduce
- reduceRight 从右到左执行
改变原数组
- splice
var a = [1,2,3,4,5,6,7,8,9];
var b = [10,11,12];
var c = a.splice(3,0,b);
c // []
a // [1, 2, 3, Array(3), 4, 5, 6, 7, 8, 9]
1
2
3
4
5
2
3
4
5
var a = [1,2,3,4,5,6,7,8,9];
var b = a.splice(3,0,4,5,6)
b // []
a // [1, 2, 3, 4, 5, 6, 4, 5, 6, 7, 8, 9]
1
2
3
4
2
3
4
var a = [1,2,3,4,5,6,7,8,9];
var b = a.splice(3,4)
b // [4, 5, 6, 7]
a // [1, 2, 3, 8, 9]
1
2
3
4
2
3
4
- push
- unshift 将元素添加在数组开头
var a = [1,2,3];
var b = a.unshift(0,4,5);
b // 6
a // [0,4,5,1,2,3]
1
2
3
4
2
3
4
- pop 删除末尾元素
var a = [1,2,3];
var b = a.pop();
b // 3
a // [1,2]
1
2
3
4
2
3
4
- shift 删除第一个元素
var a = [1,2,3];
var b = a.shift();
b // 1
a // [2,3]
1
2
3
4
2
3
4
- reverse
- sort
返回新数组
- map
- 和forEach的区别就是map返回一个新数组
- filter
← TCP三次握手与四次挥手 es6→