splice 办法
构造 1:
arr.splice(start,deletedCount) 纯删除
从 start 下标开始, 删除几个
构造 2:
arr.splice(start,deletedCount,item) 替换
从 start 下标开始, 删除几个, 并在该地位增加 item
构造 3:
arr.splice(start,0,item) 纯增加
从 start 下标开始, 删除 0 个, 并在该地位增加 item,start 开始全副往后挪动
let arr = [1,2,6,7,8];
arr.splice(2,0,3,4,5);//arr = [1,2,3,4,5,6,7,8];
slice 办法
该办法能够从数组中截取指定的字段, 返回进去
返回值: 返回截取进去的字段, 放到新的数组中, 不扭转原数组
构造 1:
arr.slice(start,end) ; 从 start 下标开始截取, 始终到 end 完结, 不包含 end
let arr = [0,1,2,3,4,5,6,7];
let newArr = arr.slice(0,3)//newArr = [0,1,2];
构造 2:
arr.slice(start) ; 从 start 下标开始截取, 始终到最初
let arr = [0,1,2,3,4,5,6,7];
let newArr = arr.slice(2)//newArr = [2,3,4,5,6,7];
构造 3:
arr.slice( ) ; 全副截取
let arr = [0,1,2,3,4,5,6,7];
let newArr = arr.slice()//newArr = [0,1,2,3,4,5,6,7];