列表操作
- concat
- 合并两个或者多个数组,它不会合并现有数组而是返回一个新数组
const array1 = [1, 2, 3]
const array2 = [4, 5, 6]
console.log(array1.concat(array2)) // [1, 2, 3, 4, 5, 6]
- copyWithin
- 浅复制数组的一部分到同一个数组中的另一个位置,并返回它,不改变原数组的长度
const array1 = [1, 2, 3, 4, 5]
console.log(array1.copyWithin(0, 3, 4)) // [4, 2, 3, 4, 5]
console.log(array1.copyWithin(1, 3)) // [4, 4, 5, 4, 5]
- fill
- 固定填充一个数组从起始索引到终止索引内的全部元素(顾头不顾尾)
const array1 = [1, 2, 3, 4];
console.log(array1.fill(0, 2, 4)) // [1, 2, 0, 0]
- filter
- 创建一个新数组,其中包含通过所提供函数实现的测试函数
const word = [1, 2, 3, 4, 5, 6]
const res = word.filter(item => item > 4) // [5, 6]